When attempting to compile and run my program in Eclipse SDK this error pops up. Ive never encountered this error message before and other posts are not very helpful. What could cause this?
问题:
回答1:
If you have a main() method and are still receiving this, the error can also appear as part of a thread error if you are also receiving a noclassdeffound error. If this is a new issue with an existing program that you have had success with before then it may be because there was a compiling error made. Delete out the compiled jar file and recompile.
回答2:
I am a newbe with Java. and the same thing happened to me after I made some changes to my projects to use a different jdk. I had changed my projects to reference jdk 1.6 instead of 1.7. Then I started getting this error. When I went to project properties->Java Compiler, I noticed that it had 1.7 in all the dropdowns. I changed the workspace settings to use 1.6 and everything started to work. It was Igor's post that led me to this resolution.
回答3:
The error says nothing about the "main" method. It says it can't find the main class...
So, I googled a little and there are lots of reasons for that: starting with wrong version of ANT (for ant-based projects) and including the java classes compiled with JRE7 and run with JRE6...
Could you please give us some more information about your environement? What do you mean by Eclipse SDK? Is it Eclipse IDE? What kind of project are you creating? Source code?
Google it a little more, there are lots of hits, one might help you.
回答4:
Right click on your project name in the project explorer, select properties, choose Java compiler, select the JRE version (like 1.6) that you installed on your system in the Compiler compliance level, then click OK and run the program! Done!
回答5:
You are trying to run a java class that doesn't have a main method. Add a main method and have it call your "starter" method.
public static void main(String[] args){
MyClass mc = new MyClass();
mc.myStarterMethod();
}
回答6:
When you run a java program, it has to know where to start. In java, the convention is a main method, with the following signature:
public static void main(string[] arguments)
When you run java program, it looks for a main method to run. That main method then can call any of your other code, but it needs a starting point.
If your program had a list of different methods, how would it know which one you wanted to run? Would you want it to just run every method it finds one time? That would be bad.
So you need something like
public static void main(string[] arguments){
System.out.println("here");
//Call your methods
//myFunction();
//doThing();
return;
}
回答7:
I suddenly had this problem where when I tried to run classes that would run perfectly fine and yes they had main() methods, I suddenly got the above error. I trid project clean and rebuild but to no avail, rather frustrating.
I had a look at the Problems tab and that said I was missing a few library jar files, I had a look in my workspace and my .java files were there but in the same place under the /bin there were no .class files, that was the reason it could not find the classes.
What I had done was moved the directory containing the library jar files, so moving those library files back, doing a restart of eclipse sorted it out.
回答8:
I had the same problem after a power trip, Eclipse wasnt compiling and starting my project. Did a project cleanup Project -> clean and it solved my problem.
回答9:
Have had similar problems with Eclipse in the path.
The best way that I've found to debug this is to go to the Run configuration dialog box, then click on the "Common" sub-tab and save the launch configuration as a "Shared file" to your project's directory.
Then you can view the launch file to see if there is anything obvious.
For example, the most recent cause for Eclipse not starting up my main class is that I had been experimenting with the maven m2eclipse plugin and that had buggered up the launch configuration such that an m2eclipse class path declaration had been added.
That told me I needed to remove the maven project type from the project which in turn cleaned out the maven/m2eclipse residuals from the launch file (automagically) and my class could then run properly. Just one of many of the interesting ways that this error can present itself.
回答10:
I've had the exact same problem in the past. The problem is that the classpath does not include the current directory. Simply add the folder in which your program resides to the CLASSPATH environment variable. Let me know if this does not work.
回答11:
You can get this if you are using a package statement, but your source code is not in the path referenced in the package statement.
回答12:
This error shown for jdk compiler version. Please use correct compiler(such as jre1.6 or 1.7) which is appropriate.
回答13:
clean and rebuild the project solved my problem.
回答14:
I had a similar problem with Eclipse IDE.
- go to run menu
- go to run configurations
- see the error on the title bar (top of screen)
- these errors are caused due to compatibility jre 1.6 or jre 1.7
- choose accordingly the execution path
- run your program