留言板

Set a variable not working

andres digiovanni,修改在11 年前。

Set a variable not working

New Member 帖子: 14 加入日期: 12-9-18 最近的帖子
Hi,

I'm trying to set a variable with the value of a method. But it doesn't work:

#set ($assetLinkLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetLinkLocalService"))
#set ($assetlinks = $assetLinkLocalService.getDirectLinks( $ae.getEntryId() ))

#set ($siz = $assetlinks.size())


But if I use this code, it print the correct value:

#set ($assetLinkLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetLinkLocalService"))
#set ($assetlinks = $assetLinkLocalService.getDirectLinks( $ae.getEntryId() ))

$assetlinks.size()


Why I can't set a variable with the value?

Regards,
Andrés
thumbnail
Ryan Schuhler,修改在11 年前。

RE: Set a variable not working

Junior Member 帖子: 77 加入日期: 12-7-6 最近的帖子
If the second code works than the first should as well. If you do want to see the print out you would have to print out the $siz variable. It would look like this:

#set ($assetLinkLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetLinkLocalService"))
#set ($assetlinks = $assetLinkLocalService.getDirectLinks( $ae.getEntryId() ))
#set ($siz = $assetlinks.size())
$siz


What is the value of the $ae variable, so I can test it?
andres digiovanni,修改在11 年前。

RE: Set a variable not working

New Member 帖子: 14 加入日期: 12-9-18 最近的帖子
The problem is that I get this error:

java.lang.NullPointerException

When I try to set a variable with the size value. The first code doesn't work.

Regards,
Andrés
thumbnail
Ryan Schuhler,修改在11 年前。

RE: Set a variable not working

Junior Member 帖子: 77 加入日期: 12-7-6 最近的帖子
It is definitely possible to set the variable with the value of the method, you already did it twice with .findService() and .getDirectLinks(). Can you attach your code so I can see where the disconnect is or why its giving you the null pointer exception?