null pointer exception on nxjlink

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: roger, 99jonathan, imaqine

null pointer exception on nxjlink

Postby benb » Mon Sep 03, 2012 9:54 am

Hi, I'm having trouble linking and uploading code to the NXT brick. Basically I'm trying to initiate a bluetooth connection but my code is split into several classes and I don't really want to post on here to avoid confusion. It compiles fine but I get the following output when trying to upload it:

Code: Select all
Linking ...
java.lang.NullPointerException
   at js.tinyvm.CodeUtilities.processMethod(CodeUtilities.java:388)
   at js.tinyvm.CodeUtilities.processCode(CodeUtilities.java:743)
   at js.tinyvm.MethodRecord.postProcessCode(MethodRecord.java:205)
   at js.tinyvm.MethodRecord.postProcessCode(MethodRecord.java:143)
   at js.tinyvm.ClassRecord.storeCode(ClassRecord.java:798)
   at js.tinyvm.Binary.processCode(Binary.java:737)
   at js.tinyvm.Binary.createFromClosureOf(Binary.java:326)
   at js.tinyvm.TinyVMTool.link(TinyVMTool.java:97)
   at js.tinyvm.TinyVMTool.link(TinyVMTool.java:48)
   at lejos.pc.tools.NXJLink.start(NXJLink.java:134)
   at lejos.pc.tools.NXJLink.run(NXJLink.java:101)
   at lejos.pc.tools.NXJLink.start(NXJLink.java:33)
   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:597)
   at lejos.pc.tools.ToolStarter.startTool(ToolStarter.java:31)
   at lejos.pc.tools.NXJLink.main(NXJLink.java:28)
Linking the file failed with exit status 1


The weird thing is that the same code used to be fine a couple of days ago, until I suddenly started getting this error. I tried looking on the forum but only found this http://lejos.sourceforge.net/forum/viewtopic.php?f=7&t=2819 that was remotely related, although probably a different problem entirely. Any idea on what I can do to try and fix it? I'm not sure what this error is even referring to...

I am running Eclipse on a Mac OSX 10.7.4 with lejos 0.9.0 and Java SE 1.7 (64-bit). Any help would be greatly appreciated, let me know if you would like the code and I'll either try and post it or send it in another way.

Thanks!
benb
New User
 
Posts: 3
Joined: Mon Sep 03, 2012 9:26 am

Re: null pointer exception on nxjlink

Postby skoehler » Mon Sep 03, 2012 11:35 am

Upgrade to 0.9.1 - or at least test 0.9.1 so we can see whether the bug is already fixed.
skoehler
leJOS Team Member
 
Posts: 1128
Joined: Thu Oct 30, 2008 4:54 pm

Re: null pointer exception on nxjlink

Postby benb » Mon Sep 03, 2012 1:39 pm

Yeah I tested it on 0.9.1 and also on a Windows 7 32-bit machine but still get the same error. I realise you won't be able to do much without replicating the error. I've made my code available here: http://people.bath.ac.uk/bb247/lejos_code/. Convoy.java is the main class, you just need to reference the .jar.

Also after some investigation it seems that commenting anything that has to do with the btConnector object in the run() method of Convoy.java solves the problem

Code: Select all
public void run() {
      // Add button listeners
      Button.ESCAPE.addButtonListener(new ButtonListener() {
         @Override
         public void buttonPressed(Button b) {
//            if(btConnector.getState() == Connector.STATE_CONNECTED) {
//               btConnector.disconnect();
//            }
            System.exit(1);
         }

         @Override
         public void buttonReleased(Button b) {
            // Do nothing
         }
      });
      
      Button.ENTER.addButtonListener(new ButtonListener() {
         @Override
         public void buttonPressed(Button b) {
//            if(btConnector.getState() == Connector.STATE_CONNECTED) {
//               btConnector.send("ping");
//            }
         }

         @Override
         public void buttonReleased(Button b) {
            // Do nothing
         }
      });
      
//      btConnector.connect(null);
   }


As I mentioned before this code was working fine a few days ago. Am I missing something really obvious?
benb
New User
 
Posts: 3
Joined: Mon Sep 03, 2012 9:26 am

Re: null pointer exception on nxjlink

Postby skoehler » Mon Sep 03, 2012 1:52 pm

Thanks for supplying the code. I will try to reproduce the error. If I am successful, I'm sure we can provide a fix.

Update: I'm happy to report that I can reproduce the error.
Update 2: The problem is known. And it's probably caused by the classes inside the JAR file. They seem to reference methods, that are not available in leJOS 0.9.1 or 0.9.0. Please ask your supervisor which leJOS version you must use.
It's rather rude of the linker to exit with a NullPointerException. It will be replaced by a proper message telling your which non-existing method is referenced.
Update 3: The error is caused by method String[] split(String, char) in class edu.bath.util.StringUtils, which is trying to invoke java.lang.String.lastIndexOf(int), which never existed in leJOS. So either, the classes in the JAR file are not compiled for use inside leJOS programs that run the NXT, or the classes inside the JAR have been improperly compiled.
skoehler
leJOS Team Member
 
Posts: 1128
Joined: Thu Oct 30, 2008 4:54 pm

Re: null pointer exception on nxjlink

Postby benb » Tue Sep 04, 2012 10:16 pm

Ok I just looked into it and turns out I wasn't compiling the jar with the NXT runtime library as you said, so I changed it and it works now. No changes needed code wise. I don't know why the library wasn't in my environment, I must've removed it without paying attention. It used to be in there, which is why the code was working fine before.
Apologies for any inconvenience caused, thanks again for the help.
benb
New User
 
Posts: 3
Joined: Mon Sep 03, 2012 9:26 am


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff