(Solved) Can’t find cause of Nullpointer

I’m getting this error, and I have no idea why:



[java]aug 26, 2012 4:27:58 PM com.jme3.network.base.DefaultClient handleError

SEVERE: Termining connection due to unhandled error

java.lang.NullPointerException

at com.jme3.network.base.MessageListenerRegistry.messageReceived(MessageListenerRegistry.java:74)

at com.jme3.network.base.DefaultClient.dispatch(DefaultClient.java:409)

at com.jme3.network.base.DefaultClient$Redispatch.messageReceived(DefaultClient.java:417)

at com.jme3.network.base.ConnectorAdapter.dispatch(ConnectorAdapter.java:133)

at com.jme3.network.base.ConnectorAdapter.run(ConnectorAdapter.java:175)[/java]



This is what happends:



[java]// login (works fine) >>

// 1. Client sends username.

// 2. Server returns randomNumber encrypted with user password (from database).

// 3. Client decrypts the message, and returns the randomNumber.

// 4. Server checks if randomNumbers match, if they do the client is logged in.

// login (works fine) <<



// get characters (causes client crashes) >>

// 1. Client sends getCharacters request-message.

// 2. Server loads CharacterData objects from the database and sends them to the client.

// 3. (crash) The client receives the CharacterData objects.

// get characters (causes client crashes) <<[/java]





The Nullpointer comes from com.jme3.network.base.MessageListenerRegistry.messageReceived:

[java] for( MessageListener<? super S> l : getListeners(m.getClass(),false) ) {

l.messageReceived( source, m ); // <— this line

delivered = true;

}[/java]





I tried putting my entire messageReceived method in a try-catch, but that didn’t fix it.

What did I do wrong?

Are you modifying the scene graph without app.enqueue?

No, I’m only System.out.println’ing the received CharacterData objects.

You added a null listener somewhere.

1 Like

Ah thanks, I’ve found it!

I forgot to check for null in my network registering class.