主线程中的Java异常-ClassNotFoundException

问题描述:

我正在使用Eclipse中的另一个系统库.有一次,图书馆以某种方式被删除了,而日食显示了一个红色的!".在项目文件夹图标旁边.我重新导入了库,但是仍然有红色的!".一旦我尝试编译并运行程序,它就会给我一个"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)

我的java文件:

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?

将评论转换为答案

在Eclipse中,右键单击项目->属性-> java构建路径->删除旧库并添加新库

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