|
-
June 28th, 2012, 04:53 PM
#1
Error: Could not find or load main class
After cleaning my Eclipse workspace I now get the error: "Error: Could not find or load main class" when I try to run any project that existed before cleaning. If a create a new project it runs as expected. I have checked all run configurations and they are indeed pointing to the correct project and main class, however Eclipse still claims this error.
What could have possibly gone wrong?
Thanks.
-
June 29th, 2012, 04:12 AM
#2
Re: Error: Could not find or load main class
Did it work before cleaning your workspace? Occasionally eclipse gets crazy, so try to restart it.
It's difficult to say without any other information.
You can also click on run manager (Button "run..." in "run" menu), where you can watch whether project, main class, classpath,.... are correct.
You can also try to compile and run from command line, or give us more information
Albert.
Please, correct me. I'm just learning.... and sorry for my english :-)
-
June 29th, 2012, 09:32 AM
#3
Re: Error: Could not find or load main class
 Originally Posted by AlbertGM
Did it work before cleaning your workspace? Occasionally eclipse gets crazy, so try to restart it.
It's difficult to say without any other information.
You can also click on run manager (Button "run..." in "run" menu), where you can watch whether project, main class, classpath,.... are correct.
You can also try to compile and run from command line, or give us more information
Albert.
1.) Yes, it did execute as expected before cleaning the workspace. I have tried restarting Eclipse, but that did not work.
2.) The project, main class and classpath are set correctly in the run configuration(s).
3.) I attempted to compile a HelloWorld class (within an existing project) and got an "Unsupported major.minor version 51.0" error. I realized this was a problem with an inconsistent JRE/JDK version (1.6/1.7 respectively). I believe the old JRE was installed as a part of a program I installed earlier in the day.
After setting the correct JRE version that problem was fixed and the class compiled and ran correctly from the command line. Still however, I get the same error (Error: Could not find or load main class code.Driver) when trying to run the same project in Eclipse.
What could be the problem? I really don't want to go through the process of rebuilding my entire workspace, but perhaps that is necessary.
-
June 29th, 2012, 02:55 PM
#4
Re: Error: Could not find or load main class
Hi,
 Originally Posted by NTL
3.) I attempted to compile a HelloWorld class (within an existing project) and got an "Unsupported major.minor version 51.0" error. I realized this was a problem with an inconsistent JRE/JDK version (1.6/1.7 respectively). I believe the old JRE was installed as a part of a program I installed earlier in the day.
You are right, this error happens when you try to run a compiled java class using an older JRE. You always can check major and minor version of a compiled java class using "javap -verbose" command.
 Originally Posted by NTL
After setting the correct JRE version that problem was fixed and the class compiled and ran correctly from the command line. Still however, I get the same error (Error: Could not find or load main class code.Driver) when trying to run the same project in Eclipse.
It looks like a classpath problem, which is not able to find code.Driver class. I've seen that mistake running java from command line and could be because classpath is wrong, or there's a wrong access to main class (by forgetting package name), or use ":" to separate JAR files in Windows (or ";" in UNIX/Linux).
Nevertheles, such mistake should never happen in eclipse, because it already builds its classpath and runs java. It's weird.
If it worked before cleaning, I'm afraid I can't help you. Just check again your 'Java build path' and Java compiler options from your project properties.
Try googling... Perhaps there's someone who has already faced that problem.
Albert
Please, correct me. I'm just learning.... and sorry for my english :-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|