Reputation: 11
I have never programmed with Java before. I tried making a HelloWorld
program, following instructions from a website. This is what my program looks like:
import java.applet.*;
import java.awt.*;
public class HelloWorld extends Applet
{
public void paint (Graphics g)
{
g.drawString("Hello World!", 50, 25);
}
}
Whenever I launch it, it says:
Could not find or load main class C:\Users\Leigh\Desktop\programs\Programming\HelloWorld.java`
Upvotes: 0
Views: 673
Reputation: 3197
You need to add main method to your HelloWorld class, like:
public static void main(String[] args) {
new HelloWorld();
}
Then your code will becomes as follows:
import java.applet.*;
import java.awt.*;
public class HelloWorld extends Applet {
public void paint(Graphics g) {
g.drawString("Hello World!", 50, 25);
}
public static void main(String[] args) {
new HelloWorld();
}
}
Upvotes: 1