wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes java.lang.NoSuchMethodError ??????? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.lang.NoSuchMethodError ???????" Watch "java.lang.NoSuchMethodError ???????" New topic
Author

java.lang.NoSuchMethodError ???????

fred fredricks
Greenhorn

Joined: Mar 04, 2003
Posts: 16
hi ppl! i have this code which i want to compile to see how it works..but its not compiling..i am a total newbie, so its probably really obvious..
i am trying to make a little image move up,down, left right when you press the arrow keys...any helps?
here is the code:
import java.awt.Graphics;
abstract class MoveableObject
{
//Draw
abstract void draw(Graphics g);

//Move, specify the speed
public void move (int direction, int s)
{
if(direction == this.RIGHT)
this.x = x + s;
if(direction == this.LEFT)
this.x = x - s;
if(direction == this.DOWN)
this.y = y + s;
if(direction == this.UP)
this.y = y - s;
}

//Overloaded, use default speed
public void move(int direction)
{
move(direction, speed);
}

// True is this object is out of the given boundary
public int outOfBound(int xBound, int yBound, int h, int w)
{
if (x < xBound)
return LEFTBOUND;
else if (x+width > xBound+w)
return RIGHTBOUND;
else if (y < yBound)
return TOPBOUND;
else if (y+height > yBound+h)
return LOWBOUND;
else
return INBOUND;

}

//Accessor
public int getWidth()
{
return width;
}
public int getHight()
{
return height;
}

//States

protected int x;
protected int y;
protected int width;
protected int height;
protected int speed;

public static final int RIGHT = 0;
public static final int LEFT = 1;
public static final int UP = 2;
public static final int DOWN = 3;


public static final int RIGHTBOUND = 0;
public static final int LEFTBOUND = 1;
public static final int TOPBOUND = 2;
public static final int LOWBOUND = 3;
public static final int INBOUND = 4;
}
Tim B.
Greenhorn

Joined: Feb 03, 2003
Posts: 10
Dear Mike,
For as far as I can see, based on your code, I think the MoveabelObject class will compile. What you probably did is compile it and then 'run' it. When you would try to run this object you will indeed get a message much like: 'Exception in thread "main" java.lang.NoSuchMethodError: main'. This is because when you 'run' a java class, it will look for the 'main' method, which will then be executed. Your file does not contain a main method, hence the error.
What you should do is create another object, containing a 'main(String args[])' method. This method could instantiate your object and do all kinda other stuff that's required to actually show your object and let the user control it.
Greetings,
Tim
Ps. The code you posted is far from finished, atleast if you had in mind that the MovableObject is the only required file. It still contains an abstract method (draw) which you must implement, else nothing will happen.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.lang.NoSuchMethodError ???????