问题
I'm working with another system library in Eclipse. One time, the library got somehow removed and eclipse showed a red "!" next to the projects folder icon. I re-imported the library, but there is still the red "!". Once I try to compile and run a program, it gives me a "ClassNotFoundException".
Exception in thread "main" java.lang.NoClassDefFoundError: MyClass
Caused by: java.lang.ClassNotFoundException: MyClass
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
My java file:
public class MyClass {
public static void main(String[] args) {
System.out.println("Test");
}
}
I don't see any mistakes in my source code. What is going on?
回答1:
Converting Comments as Answer
In eclipse rightclick on project-->properties-->java build path-->remove the old library and add new one
回答2:
Go the the Package Explorer, scroll up and right click on the name of your project (that must appear with a red cross) and then select refresh.
I was sorted out using that method. I hope it will help you.
来源:https://stackoverflow.com/questions/15588398/java-exception-in-thread-main-classnotfoundexception