Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Please help: Non-static method wait(long) cannot be referenced from static context

Reply
Thread Tools

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

 
 
Gary
Guest
Posts: n/a
 
      01-16-2004
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();
}
}
 
Reply With Quote
 
 
 
 
Ryan Stewart
Guest
Posts: n/a
 
      01-16-2004
"Gary" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: non-static method cannot be referenced from a static context Johannes Beekhuizen Java 1 08-05-2005 06:08 PM
Re: non-static method cannot be referenced from a static context Johannes Beekhuizen Java 0 08-05-2005 05:33 PM
non-static method cannot be referenced from a static context Johannes Beekhuizen Java 14 08-05-2005 04:48 PM
newbie Java question - non-static method cannot be referenced from a static context G. Burton Java 2 02-21-2004 07:45 PM
Question: non-static method dummy(int) cannot be referenced from a static context Michael Java 3 01-27-2004 08:45 PM



Advertisments