Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Wait Exception? (http://www.chiefdelphi.com/forums/showthread.php?t=80206)

NinJA999 01-14-2010 09:16 PM

Wait Exception?
 
We've been porting some of our code from last year into Java. We tried to execute a wait command, but first we had to wrap it in a try catch statement. It catches the exception with the message:
"current thread (first.team811.game2010.Team811Robot - main (pri=5)]) not owner (null)"

Is there a way we can utilize wait in Java? :confused:

derekwhite 01-15-2010 08:35 AM

Re: Wait Exception?
 
You didn't post your code, but the likely problem is that in Java you need to lock your object before doing a wait() or notify() on it. The Java wait() will unlock the object, wait until it receives a notify, then relock the object.

You can find some details on this in the Java Tutorial:
http://java.sun.com/docs/books/tutor...guardmeth.html

BradAMiller 01-15-2010 11:21 AM

Re: Wait Exception?
 
Instead of using Wait() you need to use Timer.delay(). The problem with Wait is that is a method on the Object class which is the base for all objects. So using wait doesn't really work.

First, be sure you have this import:
Code:

import edu.wpi.first.wpilibj.Timer;
Then, here is an example of using delay:
Code:

    public void autonomous() {
        System.out.println("In autonomous");
        for (int i = 0; i < 40; i++) {
            drivetrain.drive(1, 0.0);
            Timer.delay(2); // wait 2 seconds
            drivetrain.drive(-1, 0);
            Timer.delay(2);
        }
        drivetrain.drive(0.0, 0.0); // drive 0% forward, 0% turn (stop)
    }


NinJA999 01-15-2010 02:13 PM

Re: Wait Exception?
 
Great, thanks!


All times are GMT -5. The time now is 08:37 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi