Please help: Non-static method wait(long) cannot be referenced from static context

Discussion in 'Java' started by Gary, Jan 16, 2004.

  1. Gary

    Gary Guest

    submiting code with Jcreator, I get back a compiler error from line
    81, which is underlined. Using "thread.sleep" did not work either.
    What am I overlooking?

    thks
    Clueless


    c:\...\fidraf.java:81:non-static method wait(long) cannot be
    referenced from a static context
    Object.wait(2500);


    import josx.robotics.*;
    import josx.platform.rcx.*;

    public class fidraf
    {

    public static void main(String Args[])
    {

    forward();

    }
    public static void forward()
    {
    Behavior a1 = new ford();
    Behavior a2 = new turnl();
    Behavior a3 = new turnr();
    Behavior a4 = new danstop();
    Behavior a5 = new recogniz();
    Behavior [] aArray = {a1, a2, a3, a4, a5};
    Arbitrator forw = new Arbitrator(aArray);
    forw.start();
    }
    public static void reverse()
    {
    Behavior b1 = new back();
    Behavior b2 = new turnrb();
    Behavior b3 = new turnlb();
    Behavior b4 = new earthstop();
    Behavior [] bArray = {b1, b2, b3, b4};
    Arbitrator rev = new Arbitrator(bArray);
    rev.start();
    }
    public static void recog()
    {
    Behavior c1 = new ford();
    Behavior c2 = new recogniz();
    Behavior [] cArray = {c1, c2};
    Arbitrator rec = new Arbitrator(cArray);
    rec.start();
    }
    public static void canpush()
    {
    Behavior d1 = new ford();
    Behavior d2 = new edgefind();
    Behavior [] dArray = {d1, d2};
    Arbitrator can = new Arbitrator(dArray);
    can.start();
    }
    }
    class ford implements Behavior
    {

    public boolean takeControl() {
    return true;
    }

    public void suppress() {
    Motor.A.stop();
    Motor.C.stop();
    }

    public void action() {
    Motor.A.forward();
    Motor.C.forward();
    }
    }
    class recogniz implements Behavior
    {

    public boolean takeControl() {
    return Sensor.S2.readBooleanValue();
    }

    public void suppress() {
    Motor.B.stop();
    }

    public void action() {
    Motor.B.forward();
    Object.wait(2500); <<<<<<<<<<<<<<<<< Here
    Motor.B.stop();
    fidraf.canpush();
    }
    }

    class turnl implements Behavior
    {

    public boolean takeControl() {
    return Sensor.S1.readValue() < 55;
    }

    public void suppress() {
    Motor.A.stop();
    Motor.C.stop();
    }

    public void action() {
    Motor.A.stop();
    Motor.C.forward();
    }
    }


    class danstop implements Behavior
    {

    public boolean takeControl() {
    return Sensor.S3.readValue()+Sensor.S1.readValue() < 110;
    }

    public void suppress() {
    Motor.A.stop();
    Motor.C.stop();
    }

    public void action() {
    Motor.A.stop();
    Motor.C.stop();
    fidraf.recog();
    }
    }

    class earthstop implements Behavior
    {

    public boolean takeControl() {
    return Sensor.S3.readValue()+Sensor.S1.readValue() < 140;
    }

    public void suppress() {
    Motor.A.stop();
    Motor.C.stop();
    }

    public void action() {
    Motor.A.stop();
    Motor.C.stop();
    }
    }

    class turnr implements Behavior
    {

    public boolean takeControl() {
    return Sensor.S3.readValue() < 55;
    }

    public void suppress() {
    Motor.A.stop();
    Motor.C.stop();
    }

    public void action() {
    Motor.A.forward();
    Motor.C.stop();
    }
    }

    class edgefind implements Behavior
    {

    public boolean takeControl() {
    return Sensor.S3.readValue()+Sensor.S1.readValue() > 110;
    }

    public void suppress() {
    Motor.A.stop();
    Motor.C.stop();
    }

    public void action() {
    Motor.A.stop();
    Motor.C.stop();

    fidraf.reverse();
    }
    }

    class back implements Behavior
    {

    public boolean takeControl() {
    return true;
    }

    public void suppress() {
    Motor.A.stop();
    Motor.C.stop();
    }

    public void action() {
    Motor.A.backward();
    Motor.C.backward();
    }
    }

    class turnrb implements Behavior
    {

    public boolean takeControl() {
    return Sensor.S1.readValue() < 55;
    }

    public void suppress() {
    Motor.A.stop();
    Motor.C.stop();
    }

    public void action() {
    Motor.A.forward();
    Motor.C.stop();
    }
    }
    class turnlb implements Behavior
    {

    public boolean takeControl() {
    return Sensor.S3.readValue() < 55;
    }

    public void suppress() {
    Motor.A.stop();
    Motor.C.stop();
    }

    public void action() {
    Motor.A.stop();
    Motor.C.forward();
    }
    }
    Gary, Jan 16, 2004
    #1
    1. Advertising

  2. Gary

    Ryan Stewart Guest

    "Gary" <> wrote in message
    news:...
    > submiting code with Jcreator, I get back a compiler error from line
    > 81, which is underlined. Using "thread.sleep" did not work either.
    > What am I overlooking?
    >
    > thks
    > Clueless
    >
    >
    > c:\...\fidraf.java:81:non-static method wait(long) cannot be
    > referenced from a static context
    > Object.wait(2500);


    I think you want Thread.sleep(). The wait() method is used when working with
    threads to cause one thread to block until it receives a notification. And
    as your compiler is telling you, it is not a static method. It has to be
    invoked from an instance. On a side note, if you need extremely precise
    timing, Thread.sleep() won't give it to you.
    Ryan Stewart, Jan 16, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael
    Replies:
    3
    Views:
    4,936
    Adam Jenkins
    Jan 27, 2004
  2. G. Burton
    Replies:
    2
    Views:
    59,890
    Sudsy
    Feb 21, 2004
  3. Johannes Beekhuizen
    Replies:
    14
    Views:
    1,341
    John B. Matthews
    Aug 5, 2005
  4. Johannes Beekhuizen
    Replies:
    0
    Views:
    1,537
    Johannes Beekhuizen
    Aug 5, 2005
  5. Johannes Beekhuizen
    Replies:
    1
    Views:
    537
    Thomas Fritsch
    Aug 5, 2005
Loading...

Share This Page