NXTway DS Problem!!

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

NXTway DS Problem!!

Postby LAF » Wed Mar 02, 2011 11:05 am

Hello,

I have just wrote a program for my NXT with leJOS.
But while the NXT is fulfilling the Task, an error-sign pops up with:
class: 32
Method 146
Pc 11385








Here my programm:
import ch.aplu.nxt.*;
import lejos.nxt.LCD;

public class LightSensorEx1
{
public LightSensorEx1()
{
NxtRobot robot = new NxtRobot();
LightSensor ls = new LightSensor(SensorPort.S1);
LightSensor rs = new LightSensor(SensorPort.S2);
robot.addPart(ls);
robot.addPart(rs);
ls.activate(true);
rs.activate(true);
Gear gear = new Gear();
gear.setSpeed(30);
robot.addPart(gear);

while (true)
{



if ( ls.getValue()>435)
{
gear.backward(1);
}

}
}

public static void main(String[] args)
{
new LightSensorEx1();
}
}






Its not the full programm just the basics.. .to show you my problem
Just give me a hint why there is an error sign ... because it is something like a homework


Thanks for your help
LAF
New User
 
Posts: 3
Joined: Tue Mar 01, 2011 2:46 pm

Postby gloomyandy » Wed Mar 02, 2011 11:16 am

Hi,
See the leJOS FAQ post:
viewtopic.php?t=236
For instructions on how to interpret the output from the default exception handler. This should help you narrow down what the exception is and which method is causing the problem...

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

Postby LAF » Wed Mar 02, 2011 11:43 am

thanks for the quick answer...
but i can not interpret the problem: IllegalMonitorStateException

what is ment by that?
because i looked it up and it just said: when this error comes you got problems with "wait()" or sth like that


Thanks :)
LAF
New User
 
Posts: 3
Joined: Tue Mar 01, 2011 2:46 pm

Postby gloomyandy » Wed Mar 02, 2011 1:17 pm

Hi,
It looks like you essentially have all of your program in the constructor of your class. This is probably not a good idea. There are various locks held during object construction that may be causing problems. I suggest that you move as much of the code as possible from the constructor into some other method (say a method called run or whatever) than change your main code to create an instance of your class and then call the run method

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

Postby LAF » Thu Mar 03, 2011 12:31 pm

hello,

thanks for your help!
I have just solved the problem by replacing the
gear.forward(10);

with
gear.forward();
tools.delay(100);
gear.stop();



so THANKS A LOT FOR YOUR HELP! :D
LAF
New User
 
Posts: 3
Joined: Tue Mar 01, 2011 2:46 pm

Postby s.frings » Thu Mar 03, 2011 5:58 pm

Be prepared that problem repeats unless you move the program to the main() method.
s.frings
Active User
 
Posts: 131
Joined: Tue Jul 20, 2010 2:01 pm


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 0 guests

more stuff