I am really frustrated by now. I spent hours searching for an error, but I just can't find it.
I have separated the problem code from the rest and made an own program with it:
- Code: Select all
public static RemoteMotor [] mR;
public static NXTRegulatedMotor [] m = {Motor.A,Motor.B,Motor.C};
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
RemoteNXT remo = new RemoteNXT("REMO",Bluetooth.getConnector());
mR[0] = remo.A; mR[1] = remo.B; mR[2] = remo.C;
} catch (Exception e) {LCD.drawString("Damn",0,2);}
workThing();
}
public static void workThing() {
try {
LCD.drawString("Starting",0,0);
Button.waitForPress();
mR[0].rotate(180,true);
mR[2].rotate(180);
Button.waitForPress(10000);
do {
mR[1].rotate(90,true);
for (int i = 0;i<3;i++) m[i].rotate(360,true);
m[2].waitComplete();
//Delay.msDelay(270/50 * 1000); -> waitComplete() seems to work
mR[1].rotate(-90);
} while (Button.RIGHT.isPressed());
} catch (Exception e) {LCD.drawString("Fucked up",0,4);}
Button.waitForPress();
After "Starting", the system collapses and a NullPointerException (Exception 16) is thrown (before I did the try-catch myself). It is because of the rotate()-commands just following the "Starting". And if I comment them out, the same happens with the last rotate() in the loop.
Any clue why this happens with rotate? I am using rotate hundreds of times before in the same program, and it works perfectly. Only here and at another place does it collapse:
- Code: Select all
while (true) {
for (int i = 2;i>=0;i= i-1) {m[i].setSpeed(velocity); m[i].rotate(180);}
for (int i = 2;i>=0;i= i-1) {mR[i].setSpeed(velocity); mR[i].rotate(180);}
ErrorEscape();
for (int i = 0;i<3;i++) {m[i].rotate(180,true); mR[i].rotate(180,true);}
ErrorEscape(); //have to get an error response as fast as possible, therefore twice in here
}
Here, it is even stranger: the error is thrown with mR[1], after m[1-3] and mR[2] already worked perfectly!
