NullPointerException with PC API &

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

Moderators: imaqine, 99jonathan, roger

New User
Posts: 2
Joined: Thu Aug 11, 2011 8:03 am

NullPointerException with PC API &

Postby rjpaton » Fri Aug 12, 2011 4:18 am


I've just newly installed Lejos in a Windows Vista environment & I already have a problem - with one of the PC samples, I installed the latest Lejos from Source Forge using the executable and I note that it sets up the right environment variables etc. I want to run with the NXT unflashed as my kids still use the Mindstorms programs, so I thought I would try out the PC API and so I compiled which went without a problem using nxjpcc Then I turn on the NXT, and turn on Bluetooth (I have verified it connects to my PC) and then when I run it - 'nxjpc TachoCount' - it starts by spinning motor A but then errors out in the following way (here is the onscreen text when I run it):

>nxjpc TachoCount
Protocols = 2
Search Param = NXT
Searching cache file for known Bluetooth devices
Found NXT 0016530CCFFA in cache file
Found 1 matching NXTs in cache file
Connecting to NXT 0016530CCFFA in mode 1
BlueCove version 2.1.0 on widcomm
Connected to NXT
Tachometer A: 0
Tachometer C: 0
Exception in thread "main" java.lang.NullPointerException
at lejos.nxt.remote.RemoteMotor.waitComplete(
at lejos.nxt.remote.RemoteMotor.rotate(
at lejos.nxt.remote.RemoteMotor.rotate(
at RobotEyeDemo.main(
BlueCove stack shutdown completed

Can anyone tell me what I've got wrong here - I thought this example program should just run fine 'out of the box'.


User avatar
leJOS Team Member
Posts: 5995
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: NullPointerException with PC API &

Postby gloomyandy » Fri Aug 12, 2011 9:28 am

Yes this is a known issue introduced in 0.9.0. See this thread for some details and a work around
To work around the issue you basically need to install a RegulatedMotorListener using the addListener method: ... orListener)
You don't need to take any notice of the call backs just install it...


New User
Posts: 2
Joined: Thu Aug 11, 2011 8:03 am

Re: NullPointerException with PC API &

Postby rjpaton » Tue Aug 23, 2011 7:19 am

Thanks Andy for pointing that out and Dominik for your solution. However, I still have not been able to get it to work. I thought I would get around the problem sort of 'quick & dirty' so I pasted the class definition for the listener (from Dominik) into my class and then added the creation of the listener as follows in the main().

// Initialise the motors & listeners
RegulatedMotorListener listener1 = new MotorListener();

However, when I go to compile it I get the following error message:

81: non-static variable this cannot be referenced from a static context
RegulatedMotorListener listener1 = new MotorListener();

Sorry if I'm being thick, but what am I doing wrong?


Return to “NXJ Software”

Who is online

Users browsing this forum: No registered users and 5 guests