在 Eclipse 中清理项目后未找到类异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15655740/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Class Not Found Exception after cleaning project in Eclipse
提问by Devin
I am currently working on a Java project in Eclipse that includes 44 java files and 1 SQL file. After working on it for several hours today, I noticed that nothing I was doing affected the program when I ran it (I could delete all the code in the main class and it still ran fine). I checked the class files and noticed they had not been modified for several days (since the last time I worked on it). After doing some reading online, I took the advice to perform Project->Clean. However, after doing that, I can no longer compile the project. When I run the main class I simple get this:
我目前正在 Eclipse 中处理一个 Java 项目,其中包括 44 个 Java 文件和 1 个 SQL 文件。今天工作了几个小时后,我注意到当我运行它时我没有做任何事情影响程序(我可以删除主类中的所有代码,它仍然运行良好)。我检查了类文件,发现它们已经好几天没有被修改了(自从我上次处理它以来)。在网上做了一些阅读之后,我接受了执行 Project->Clean 的建议。但是,这样做之后,我无法再编译该项目。当我运行主类时,我很简单地得到了这个:
Exception in thread "Thread-1" java.lang.NoClassDefFoundError: sprint1/Main2
Caused by: java.lang.ClassNotFoundException: sprint1.Main2
at java.net.URLClassLoader.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)
I have checked the build path and from what I can tell everything seems correct. I have also toggled Project->Build Automatically on and off to no avail. The only thing I can think of to do now is create a new project and copy all the code to it, but I am using various obscure jars and SWT (which doesn't transfer well, if at all, in my experience). Can anyone help me out with this?
我已经检查了构建路径,据我所知,一切似乎都是正确的。我还打开和关闭了 Project->Build Automatically 也无济于事。我现在唯一能想到的就是创建一个新项目并将所有代码复制到其中,但我使用了各种晦涩的 jar 和 SWT(根据我的经验,它不能很好地传输,如果有的话)。谁能帮我解决这个问题?
回答by Plinio FM
Check if exists any error in your project. Not just the compilation errors. Click on project and check the "Problems" view in Eclipse.
检查您的项目中是否存在任何错误。不仅仅是编译错误。单击项目并检查 Eclipse 中的“问题”视图。
I think it happens usually when there is any JAR file missing in the project. Even if you don't use it.
我认为这通常发生在项目中缺少任何 JAR 文件时。即使你不使用它。
Select Project in the Eclipse -> right button -> Properties -> Java Build Path -> Libraries tab
在 Eclipse 中选择 Project -> 右键 -> Properties -> Java Build Path -> Libraries 选项卡
And check any red mark in the JAR files. Remove it of your Eclipse Project or fix the path (select JAR and click Edit button).
并检查 JAR 文件中的任何红色标记。从 Eclipse 项目中删除它或修复路径(选择 JAR 并单击编辑按钮)。
回答by Premsuraj
Are you sure there are no build errors in any of your classes? If there are errors, eclipse would could run the previous error free version (according to some settings you provide). Build errors can also lead to the class files not being generated after a project clean.
您确定您的任何类中都没有构建错误吗?如果有错误,eclipse 会运行之前的无错误版本(根据你提供的一些设置)。构建错误还可能导致在项目清理后未生成类文件。