2

My java project has a class with a main method. I an project clean and build via eclipse after which I am getting the following error: Any ideas on how to troubleshoot this further (I know there are others who mentioned the same case) - I want to figure out how to troubleshoot this further (not look at individual cases for everyone).

Error: Could not find or load main class

I am using JDK1.7 & Eclipse (Kepler release)

Edit: Found the error: it was due to a type (and its quite disappointing that eclipse did not generate an error message stating what it was trying to load - my fault obviously since I did not check what was being loaded

  • What does your run config look like? Or, how are you running your project? Do you right click on the class with the `main` method and select Run As... > Java Application? – David Conrad Aug 19 '14 at 19:02
  • I have tried the run as java application in eclipse - says could not find or laod main class (this happened after I ran clean on the project via eclipse) –  Aug 19 '14 at 19:20
  • But *where* are you clicking on run as java application? On the context menu after right clicking on your class, on the "Run" menu, or somewhere else? – David Conrad Aug 19 '14 at 19:29
  • I found the error - will update the post or simply delete it - it was due to a typo (and eclipse error messages are not clear enough) –  Aug 19 '14 at 19:30

3 Answers3

3

Ya, I too got the same error once.What I did is:-

  1. Right click on the project in eclipse
  2. click run as --> run configurations
  3. there u can see the java application some where under the 'type filter text box'. right click and click new.
  4. then give the project name and main class name and then click run after selecting the created application settings.

Hope this helps.

benka
  • 4,732
  • 35
  • 47
  • 58
Sudhir kumar
  • 549
  • 2
  • 8
  • 31
1

You need to check if your classpath variable is set

export CLASSPATH=/tmp
java Tester

Also check that you add the location of your .class file to your classpath.

Also try Project>Clean and Project>Build Project

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
1

There is some problem with your classloader, somehow it is not generating the .class. When you clean it, it deletes all the .class files, and when you build it, it generates the .classes again.

Eclipse has its own compiler, maybe it is not working correctly.

Did you try closing and opening Eclipse again?

Bruno Franco
  • 2,028
  • 11
  • 20
  • Have a look at my configurations, it may help you: http://postimg.org/image/60rdcv7zp/ It has the default compliance settings, that generate the class files compatibility with the jdk. – Bruno Franco Aug 19 '14 at 19:00
  • tried that - there's something else messed up with my eclipse project (besides my head spinning) –  Aug 19 '14 at 19:21