Exception in message disptach; dropping message

Hi @ll,

i am from germany and english was never one of my favorite subjects in the school but i try my best that you can understand me :slight_smile:

I tried to make a simple multiplayer game - my work based on the “SGS Tank” example. My problem is now, that i get this exception if my client received a message from the server:

06.04.2007 13:57:35 com.sun.sgs.impl.io.CompleteMessageFilter processReceiveBuffer
WARNUNG: Exception in message disptach; dropping message
java.lang.NullPointerException
at de.kangee.game.pingpong.client.gamemanagement.GameManager.receivedMessage(GameManager.java:406)
at com.sun.sgs.client.simple.SimpleClient$SimpleClientChannel.receivedMessage(SimpleClient.java:608)
at com.sun.sgs.client.simple.SimpleClient$SimpleClientConnectionListener.handleChannelMessage(SimpleClient.java:486)
at com.sun.sgs.client.simple.SimpleClient$SimpleClientConnectionListener.receivedMessage(SimpleClient.java:348)
at com.sun.sgs.impl.client.simple.SimpleClientConnection.bytesReceived(SimpleClientConnection.java:131)
at com.sun.sgs.impl.io.SocketConnection.filteredMessageReceived(SocketConnection.java:108)
at com.sun.sgs.impl.io.CompleteMessageFilter.processReceiveBuffer(CompleteMessageFilter.java:108)
at com.sun.sgs.impl.io.CompleteMessageFilter.filterReceive(CompleteMessageFilter.java:75)
at com.sun.sgs.impl.io.SocketConnectionListener.messageReceived(SocketConnectionListener.java:100)
at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageReceived(Unknown Source)
at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(Unknown Source)
at org.apache.mina.common.support.AbstractIoFilterChain.access$5(Unknown Source)
at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(Unknown Source)
at org.apache.mina.filter.executor.ExecutorFilter.processEvent(Unknown Source)
at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
at java.lang.Thread.run(Thread.java:595)

The code of my recieved method:

public void receivedMessage(ClientChannel arg0, SessionId arg1, byte[] arg2) {
	
	PosUpdateMsg message = new PosUpdateMsg();
	message.parseMsg(new String(arg2));
	if(this.playerMap.get(arg1.toString()) != null)
	{
		
		Sprite s = this.playerMap.get(arg1.toString());
		s.setX(message.getX());
		s.setY(message.getY());
		
	}else
	{
		Sprite s = new DefaultPlayer(GameUtils.p1Animation);
		s.setX(message.getX());
		s.setY(message.getY());
                    this.playerMap.put(arg1.toString(), s);
		this.sprites.add(s);
	}
			
}

Which line is line 406 of GameManager.java?

Also, note that a channel message from the server will have a null SessionId, which will cause arg1.toString() to throw NullPointerException.

(BTW you’re better off using a SessionId directly instead of calling toString on it. A SessionId defines equals() and hashCode(), but there are no guarantees on the uniqueness of the String representation of a SessionId)

Line: if(this.playerMap.get(arg1.toString()) != null

Ok - that was the reason. THX for your help!

By the way.

Whenever I run into something like a Null pointer or other strange value I cant explain, my first step is to trace it in a debugger and look at the actual values of variables.

Eclipse and Netbeans are both free and have excellent built in debuggers 8)