Java Exception in thread main - ClassNotFoundException

做~自己de王妃 提交于 2019-12-11 04:53:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!