java NoClassDefFoundError 但类存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6223828/
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
NoClassDefFoundError but class exists
提问by Darkhydro
Here is the error:
这是错误:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: sfclocator/UpdateNameForm
at sfclocator.SFCViewer.(SFCViewer.java:68)
at sfclocator.SFCViewer.run(SFCViewer.java:1823)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.ClassNotFoundException: sfclocator.UpdateNameForm
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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
I created this program as a Netbeans 7.0 project. I've been working on it for about 2-3 days, and finished it yesterday. It worked perfectly yesterday. I went to sleep, woke up, ran it this morning, and all of a sudden I got errors. I fixed the errors that popped up, except for this one.
我将此程序创建为 Netbeans 7.0 项目。我已经工作了大约 2-3 天,昨天完成了。昨天效果很好。我去睡觉,醒来,今天早上运行它,突然间我出错了。我修复了弹出的错误,除了这个。
The project builds perfectly, and the JAR even runs just fine, but when I try to run the project using Netbeans it gives me this error. Any help would be appreciated.
该项目构建完美,JAR 甚至运行得很好,但是当我尝试使用 Netbeans 运行该项目时,它给了我这个错误。任何帮助,将不胜感激。
Further information i just found out:
我刚刚发现的更多信息:
When built, the UpdateNameForm class exists in the classes folder of netbeans project, but when i click run, it deletesthe UpdateNameForm classes.
构建时,UpdateNameForm 类存在于 netbeans 项目的 classes 文件夹中,但是当我单击运行时,它会删除UpdateNameForm 类。
采纳答案by Darkhydro
I have solved my problem by creating a new netbeans project from the existing sources. In my opinion, this is not a good way to do things (especially on large projects) but none of the existing answers provided a solution.
我通过从现有源创建一个新的 netbeans 项目解决了我的问题。在我看来,这不是做事的好方法(尤其是在大型项目中),但现有的答案都没有提供解决方案。
回答by Nik
i had a similar problem, i resolved it by first removing the jar from the build path and then adding it again. Build the project after re-adding the jar. Sometimes the build path is not refreshed... i hope this works for u too.
我有一个类似的问题,我通过首先从构建路径中删除 jar 然后再次添加它来解决它。重新添加jar后构建项目。有时构建路径没有刷新......我希望这也适用于你。
回答by Odd Steen
I suddenly had the same problem. I checked the output of the build process in /build/classes and couldn't find the missing class. No wonder about the error message... My way to fix this in NetBeans 8.2 was to right-click on the project to open the Properties page. Then go to Compiling under Build and uncheck the Compile on Save box. After that I did some dummy editing of the problematic class - entering a System.out... and deleting it again - and save. After that I could right-click on the class and chose Compile File. Again checking in /build/classes I could see that the classes were now built. Running the program worked and I could re-check the Compile on Save box in the project Properties.
我突然遇到了同样的问题。我在 /build/classes 中检查了构建过程的输出,但找不到丢失的类。难怪错误消息... 我在 NetBeans 8.2 中修复此问题的方法是右键单击项目以打开“属性”页面。然后转到 Build 下的 Compiling 并取消选中 Compile on Save 框。之后,我对有问题的类进行了一些虚拟编辑 - 输入 System.out... 并再次删除它 - 并保存。之后,我可以右键单击该类并选择编译文件。再次检查 /build/classes 我可以看到现在已经构建了类。运行程序有效,我可以重新检查项目属性中的“保存时编译”框。
回答by Bohemian
These kinds of problems are almost always due to classpath issues.
这些类型的问题几乎总是由于类路径问题。
- Check your classpath setting
- Check that the jar containing your class can be found in the execution environment
- Check that the class isn't in another jar found earlier in your classpath - especially an earlier/later version of the jar (ie if you've upgraded but not cleared out your old jars)
- 检查您的类路径设置
- 检查在执行环境中是否可以找到包含您的类的 jar
- 检查该类是否不在您的类路径中较早找到的另一个 jar 中 - 特别是该 jar 的早期/更高版本(即,如果您已升级但未清除旧的 jar)
If you don't know which jar your class is in, I find this site invaluable to help you find out: http://www.jarfinder.com
如果您不知道您的班级在哪个 jar 中,我发现这个网站非常有用,可以帮助您找到:http: //www.jarfinder.com