helper.getUserById throws Exception (not string issue)

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

Moderators: Lapo, Bax

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

helper.getUserById throws Exception (not string issue)

Postby gl0om » 29 Sep 2010, 12:29

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]
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 29 Sep 2010, 19:24

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

Postby gl0om » 29 Sep 2010, 19:56

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

Postby gl0om » 29 Sep 2010, 20:31

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

Postby appels » 30 Sep 2010, 03:11

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 ?
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 30 Sep 2010, 04:40

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:

Postby appels » 30 Sep 2010, 09:25

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.

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 20 guests