NullPointerException with PC API & TachoCount.java

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

Moderators: imaqine, 99jonathan, roger

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

NullPointerException with PC API & TachoCount.java

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

Hi

I've just newly installed Lejos in a Windows Vista environment & I already have a problem - with one of the PC samples, TachoCount.java. 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 TachoCount.java which went without a problem using nxjpcc TachoCount.java. 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(RemoteMotor.java:190)
at lejos.nxt.remote.RemoteMotor.rotate(RemoteMotor.java:171)
at lejos.nxt.remote.RemoteMotor.rotate(RemoteMotor.java:205)
at RobotEyeDemo.main(RobotEyeDemo.java:41)
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'.

Thanks
Rob

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

Re: NullPointerException with PC API & TachoCount.java

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

Hi,
Yes this is a known issue introduced in 0.9.0. See this thread for some details and a work around
viewtopic.php?f=7&t=2837&p=13881&hilit=+NullPointerException#p13881
To work around the issue you basically need to install a RegulatedMotorListener using the addListener method:
http://lejos.sourceforge.net/nxt/pc/api ... orListener)
You don't need to take any notice of the call backs just install it...

Andy

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

Re: NullPointerException with PC API & TachoCount.java

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();
Motor.A.addListener(listener1);

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?


Thanks
Robert


Return to “NXJ Software”

Who is online

Users browsing this forum: No registered users and 5 guests