helper.getUserById throws Exception (not string issue)

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

helper.getUserById throws Exception (not string issue)

Post by gl0om »

Code: Select all

public void _handleRequest(String cmd, org.json.JSONObject data, User fromUser, int fromRoom)
{
	... skipped ...
	int avatar_id = data.getInt("avatar_id");
	User target = helper.getUserById(avatar_id); //line 195
	... skipped ...
}
throws

java.lang.NullPointerException
at test.CustomOSExtension._handleRequest(CustomOSExtension.java:195)
at com.smartfoxserver.openspace.OpenSpaceExtension.handleRequest(OpenSpa
ceExtension.java:202)
at it.gotoandplay.smartfoxserver.controllers.ExtensionHandler.processEve
nt(ExtensionHandler.java:500)
at it.gotoandplay.smartfoxserver.controllers.ExtensionHandler.run(Extens
ionHandler.java:344)
at java.lang.Thread.run(Thread.java:619)

I have no idea why. Please help.[/code]
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

It usually throws that exception when you attempt to call a method on a null variable.

so for example, if data was null - java would throw the java.NullPointerException if you try and do this --> data.getSomething()
Smartfox's forum is my daily newspaper.
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Post by gl0om »

No, data is ok. First thing I checked was data. Tracing avatar_id shows me correct number.
gl0om
Posts: 54
Joined: 30 Mar 2010, 17:39

Post by gl0om »

oops, my inattention, helper was uninitialized...
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Post by appels »

i'm getting the same although all seems to work fine :
2010/09/30 05:39:33.621 - [ WARNING ] [id: 27] (JavascriptExtension.logASError): Error in extension [ customLogin.as ]: TypeError: Cannot call method "getUserId" of null (customLogin.as#1607) Internal: 32 -- Line number: 31 in file: customLogin.as

I call the getUserId() each time a user is logged.
Is there a way to avoid it getting called if the data is a null value ?
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

well, you could do something like this

if (data != null)
data.getUserId()

but, it's best to avoid that where possible. Try and find out the cause of null value.
Smartfox's forum is my daily newspaper.
appels
Posts: 464
Joined: 28 Jul 2010, 02:12
Contact:

Post by appels »

yes, i was already trying to find out what's causing it. Just can't seem to find it for the moment, will do some more debugging.
Post Reply