Eclipse Error: Could not find or load main class [duplicate]

Have Googled extensively on this error, but I can't seem to fix the problem. I've written a basic java program in Eclipse Juno, as follows:

public class HelloWorld {

    /**
     * @param args
     */

    public static void main(String[] args) {
        System.out.println("Hello Eclipse!");
    }

}

After clicking Run, I get: "Error: Could not find or load main class HelloWorld". This error message applies to all my other projects in the same workspace. I've tried switching workspaces but the error still appears.

I'm on Windows 7 64-bit. Any help would be appreciated!


Solution 1:

This just happened to me today after updating my JRE. I cleaned the project and it started working again.

Project -> Clean will remove any existing class files and completely rebuild the project. There's more information on Eclipse's clean function here.

Solution 2:

I just ran into that problem. The cause... not sure. However, only happened after I added a new jvm. My solution:

  • went to run configurations: - run->run configurations

In the Classpath tab:

  • Select Advanced
  • Add where Eclipse usually put the *.class for the projects, which is in bin. So I added the bin directory for the project.

I hope it helps someone out there. It took me time to figure this out.

Solution 3:

I deleted a jar file from the bin directory. Right click on your project - Properties then Libraries tab. There was a red flag in there. I removed the jar file from the Libraries and it worked.

Solution 4:

It seems that the class is not compiled by Eclipse.

Few pointers could be-

  1. Check if the .class file exists in your output folder.To know your output folder Right Click on Project->Properties->Java Build Path(Check at bottom).
  2. Check if Project->build Automatically is checked in the menu.
  3. Check if the HelloWorld class is in src folder or not.Right Click on Project->Properties->Java Build Path(Check source tab).