Eclipse error: could not find or load the main class

Correct this error on Google, but I cannot solve the problem. I wrote 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 the Run button, I get: "Error: Could not find or load the main HelloWorld class." This error message applies to all my other projects in the same workspace. I tried switching workspaces, but the error still appears.

I am on a 64-bit version of Windows 7. Any help would be appreciated!

+55
java eclipse
May 02 '13 at 9:30
source share
8 answers

I just ran into this problem. Reason ... not sure. However, this only happened after I added a new jvm. My decision:

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

In the Classpath tab:

  • Select Advanced
  • Add where Eclipse usually puts * .class for projects that are in bin. So I added the bin directory for the project.

I hope this helps someone out there. It took me a while to figure this out.

+74
Jun 28 '13 at 1:47
source share
— -

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

Project -> Clean will delete all existing class files and completely rebuild the project. There is more information about the Eclipse clean function here .

+65
Jan 16 '14 at 19:15
source share

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

+38
10 sept. '13 at 18:52
source share

It seems that the class is not compiled by Eclipse.

Multiple pointers may be -

  • Check if the .class file exists in the output folder. To find out your output folder Right-click Project-> Properties-> Java Build Path (check below).
  • Make sure Project-> build Automatically is checked in the menu.
  • Check if the HelloWorld class is in the src folder or not. Right click on Project-> Properties-> Java Build Path.
+12
May 2 '13 at 9:37
source share

The same thing happens to me. I went to project> properties> javaBuildPath.

There, in order of export, I moved my java / main to a higher bias

+10
Sep 13 '13 at 10:24
source share

because you guys created the class once with the main method, and after that it may be that you deleted this form or workspace, and yet some of the files exist, I suggest you create this form or workspace again, and then delete it by clicking on it completely, and then if you created some class like Runner, try to run it again.

+3
Sep 03 '13 at 0:47
source share

It happened to me. I noticed that someone said that I have to create a whole new WORKSHOP! What for? Because I installed a newer version of JRE, and this will not allow to run other previous versions. So all these old files I became useless. Not really, just copy and paste it into a new class and replace it with an unused class name.

0
Jun 01 '13 at 2:52 on
source share

if your package name matches your class name, this problem will occur.

-7
Sep 07 '13 at 3:04 on
source share



All Articles