Java Error

Goonie

Lonely End of the Rink
Joined
Nov 29, 2002
Messages
3,312
Location
Kingston
I have an assignement to do(first with graphics) and no more that 20 mins in I have an error when I run the program. I can compile fine, but when I run the program I get this error.
"Exception in Thread "main" java.lang.NoSuchMethodError: main"

Here is my code.

"import java.applet.Applet;
import java.awt.*;


public class BlackPearl extends Applet{

private Button cruising, blackpearl, visitors;
private boolean isCruising=true;


public void init()
{
cruising=new Button("Crusing");
blackpearl=new Button("Blackpearl");
visitors=new Button ("Visitors");

add (cruising);
add (blackpearl);
add (visitors);

}
public void paint (Graphics g)
{
g.setColor(Color.cyan);
g.fillRect(0,0,400,400);
g.setColor(Color.white);
g.fillOval(100,40,100,100);
g.setColor(Color.red);
}

}
"
 
To run it using the command "java BlackPearl" you need a method called "public static void main (String[] args) {}" that inits the program. But since this is an applet, it has to be viewed in a browser (from an HTML file) or an applet viewer. Search the net to see how you set up a webpage to view the applet.:)
 
if this is a run time error - i think the command you should be using is "AppletViewer BlackPearl.xxxx" with .java or .html where xxxx is (instead of "java BlackPearl". However it has been a while since i've done anything with applets. And i did it with the javax JApplet, not the Applet too.
 
This is really weird guys. It works now.... I use JCreator, and I used the other run button and it worked. Talk about freaky...

Edit: Thanks for the suggestions though.
 
I use JCreator too, LE, it really speeds up the time-consuming parts in DOS. It doesn't seem to have a Run-button though, only a Compile-button, Compile Project-button, an Execute-button and an Execute Project-button. I assume there's quite a difference between the normal and project buttons if you have more than one file in your project.
 
Back
Top Bottom