Exception on task execution

i was using the swordworld demo to build my app. and i encounter this error:

Jun 14, 2006 2:35:11 AM com.sun.gi.logic.impl.SimTaskImpl execute
WARNING: Exception on task execution:
target: com.sun.gi.apps.swordworld.server.Player
method: userDataReceived
declared on: com.sun.gi.logic.SimUserDataListener
java.lang.NullPointerException
at com.sun.gi.logic.impl.SimulationImpl.sendUnicastData(SimulationImpl.java:496)
at com.sun.gi.logic.impl.DeferredUnicast.execute(SimTaskImpl.java:574)
at com.sun.gi.logic.impl.SimTaskImpl.processDeferredCommands(SimTaskImpl.java:536)
at com.sun.gi.logic.impl.SimTaskImpl.execute(SimTaskImpl.java:188)
at com.sun.gi.logic.impl.SimThreadImpl.run(SimThreadImpl.java:105)

whenever it executes this code: task.sendData(appChannel,uid,outbuff,true);
i have done this: simTask.addUserDataListener(uid,playerRef);

i am trying to send data from the client to the server and vice versa.

can someone kindly advise if i miss out anything or do the wrong way? :’(

Hmm.

You shoudl only need to do the addUserDataListener call once. It should be done in the task the executes in response to the userJoined() callback.

The error you are getting says to me that the parameters passed in sendData somehow resulted in a null pointer reference when trying
to actually execute the send (it gets delayed until the task finishes to preserve the transactional nature.)

Can you show me the peice of code you currently have in the few lines before and after sendData line?

here’s my code:

public void userDataReceived(UserID from, ByteBuffer data){		
	byte[] inbytes = new byte[data.remaining()];
	data.get(inbytes);
	
	String commandString = new String(inbytes).trim();
	
	System.out.println("dataReceived ="+commandString + "from");
	System.out.print("User ID ="+from);
	
	String[] words = StringUtils.explode(commandString," ");	
	SimTask simTask = SimTask.getCurrent();
	/**/Room roomGLO = currentRoomRef.get(simTask);
	ByteBuffer outbuff = null;
	
	if (words[0].equalsIgnoreCase("look")){			
		try {
			 GLOReference<Player> myRef = simTask.lookupReferenceFor(this);
			 String out = roomGLO.getDescription(myRef);
			 
			 System.out.println("roomGLO description = " + out);
			 System.out.println("description length = " + out.length());
			 System.out.println("data.getBytes = " + out.getBytes());
			 outbuff = ByteBuffer.allocate(out.length());
			 outbuff.put(out.getBytes());
			 
		} catch (Exception e) {	
			System.out.println("Failed to create this-reference");
			e.printStackTrace();
		}/**/
	}
	
	if(words[0].equalsIgnoreCase("name")){
		System.out.println("in player: player name is " + this.name);
		outbuff = ByteBuffer.allocate(this.name.length());
		outbuff.put(this.name.getBytes());
	}
	
	if(outbuff != null){
		simTask.sendData(appChannel,from,outbuff,true);
	}
}

Where is appChannel being set?

Try either debugging or inserting printlns right ebofe the sendTask to check the values of all parameters.

Im guessing either appChannel or outbuff is null in the case where you are seeing the exception.

jeff, i added a few println before the simtask operations. it seems that the outbuff is null/empty. i’m puzzled. how comes it doesnt works here as the coding is exactly the same as earlier working version. ???

code provided in the swordworld:
GLOReference myRef = simTask.lookupReferenceFor(this);
String out = roomGLO.getDescription(myRef);
ByteBuffer outbuff = ByteBuffer.allocate(out.length());
outbuff.put(out.getBytes());
simTask.sendData(appChannel,from,outbuff,true);

my code:
GLOReference myRef = simTask.lookupReferenceFor(this);
String out = roomGLO.getDescription(myRef);
byte[] dest = new byte[out.length()];

System.out.println("in player: roomGLO description = " + out);
System.out.println("in player: description length = " + out.length());
System.out.println("in player: data.getBytes = " + out.getBytes());

ByteBuffer outbuff = ByteBuffer.allocate(out.length());
outbuff.put(out.getBytes());

System.out.println("appChannel: " + appChannel);
System.out.println("send to userID: " + from);
System.out.println("send to outbuff: " + outbuff.get(dest));

simTask.sendData(appChannel,from,outbuff,true);

output:
User ID =UUID(1150464745429:-6021726462601109706)dataReceived =lookfrom
User ID =UUID(1150464745429:-6021726462601109706)in player: roomGLO description = You are in A big brightly lit room. containing:
A shiney new sword
With you in the room are:

in player: description length = 93
in player: data.getBytes = [B@2344b18f
appChannel: UUID(1150429122430:4214629083300757772)
send to userID: UUID(1150464745429:-6021726462601109706)
Failed to create this-reference
java.nio.BufferUnderflowException
at java.nio.HeapByteBuffer.get(HeapByteBuffer.java:127)
at java.nio.ByteBuffer.get(ByteBuffer.java:674)
at com.sun.gi.apps.swordworld.Player.userDataReceived(Player.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.gi.logic.impl.SimTaskImpl.execute(SimTaskImpl.java:186)
at com.sun.gi.logic.impl.SimThreadImpl.run(SimThreadImpl.java:105)

after doing the following:

  1. ps -e
  2. kill java
  3. rm -r persistant_store
  4. restart the discoverer and sgs
  5. run my client
  6. IT WORKS.

hmm… ::slight_smile: so… i’m really wondering if the issue lies in the backend of the sgs / object store and not my coding.

AH…

Okay here is what was happenign I THINK…

(1) Because the store was bad. The serevr was coming up but failign to fully star tand comign up ina bad state
(2) Your second attempt to start it was doing nothign ebcause the firstw as still running.
(2) That bad state of the running server caused you to recieve a null buffer in the callback somehow.

I dont know why the last happened, Id have to look at the code closer, but atleast youve got it workign now for you 8)

  1. hmm, perhaps it’s so i guess. in the meanwhile i will crossed my fingers that it wont happend again. if it does, i will do the required steps. haha.