user3066803
user3066803

Reputation: 11

"Could not find or load main class" What does this mean?

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

Answers (1)

Mengjun
Mengjun

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

Related Questions