简体   繁体   中英

Java Exception in thread main - ClassNotFoundException

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?

Converting Comments as Answer

In eclipse rightclick on project-->properties-->java build path-->remove the old library and add new one

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM