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

G

Gary

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();
}
}
 
R

Ryan Stewart

Gary said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,979
Messages
2,570,184
Members
46,721
Latest member
DollieSawt

Latest Threads

Top