Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Exception on task execution  (Read 2232 times)
0 Members and 1 Guest are viewing this topic.
Offline emerald

Senior Newbie





« Posted 2006-06-13 20:40:51 »

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? Cry

feelin rusty
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2006-06-13 23:22:46 »

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?

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline emerald

Senior Newbie





« Reply #2 - Posted 2006-06-14 06:15:13 »

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);
      }
   }

feelin rusty
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #3 - Posted 2006-06-14 22:06:40 »

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.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline emerald

Senior Newbie





« Reply #4 - Posted 2006-06-16 06:17:39 »

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.  Huh

code provided in the swordworld:
GLOReference<Player> 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<Player> 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)

feelin rusty
Offline emerald

Senior Newbie





« Reply #5 - Posted 2006-06-16 16:31:04 »

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...  Roll Eyes so... i'm really wondering if the issue lies in the backend of the sgs / object store and not my coding.

feelin rusty
Offline Jeff

JGO Coder




Got any cats?


« Reply #6 - Posted 2006-06-16 21:46:12 »

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 Cool

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline emerald

Senior Newbie





« Reply #7 - Posted 2006-06-17 18:31:39 »

 Cool 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.

feelin rusty
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (54 views)
2014-04-15 18:08:23

BurntPizza (53 views)
2014-04-15 03:46:01

UprightPath (66 views)
2014-04-14 17:39:50

UprightPath (49 views)
2014-04-14 17:35:47

Porlus (66 views)
2014-04-14 15:48:38

tom_mai78101 (90 views)
2014-04-10 04:04:31

BurntPizza (151 views)
2014-04-08 23:06:04

tom_mai78101 (246 views)
2014-04-05 13:34:39

trollwarrior1 (204 views)
2014-04-04 12:06:45

CJLetsGame (211 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!