NoClassDefFoundError 但类存在
错误如下:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: sfclocator/UpdateNameForm
at sfclocator.SFCViewer.(SFCViewer.java:68)
at sfclocator.SFCViewer$10.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$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:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
我将此程序创建为 Netbeans 7.0 项目。我花了大约2-3天的时间,昨天完成了。昨天效果很好。我睡觉了,醒来,今天早上运行它,突然出现错误。我修复了弹出的错误,除了这个错误。
该项目构建完美,JAR 甚至运行得很好,但是当我尝试使用 Netbeans 运行该项目时,它给了我这个错误。任何帮助将不胜感激。
我刚刚发现的更多信息:
构建时,UpdateNameForm 类存在于 netbeans 项目的类文件夹中,但是当我单击运行时,它删除 UpdateNameForm 类。
Here is the error:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: sfclocator/UpdateNameForm
at sfclocator.SFCViewer.(SFCViewer.java:68)
at sfclocator.SFCViewer$10.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$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: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.
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.
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 deletes the UpdateNameForm classes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我有一个类似的问题,我通过首先从构建路径中删除 jar 然后再次添加它来解决它。重新添加 jar 后构建项目。有时构建路径不会刷新...我希望这也适合你。
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.
我突然遇到了同样的问题。我检查了 /build/classes 中构建过程的输出,但找不到丢失的类。难怪会出现错误消息...我在 NetBeans 8.2 中解决此问题的方法是右键单击项目以打开“属性”页面。然后转到“构建”下的“编译”并取消选中“保存时编译”框。之后,我对有问题的类进行了一些虚拟编辑 - 输入 System.out...并再次删除它 - 并保存。之后,我可以右键单击该类并选择编译文件。再次检查 /build/classes 我可以看到类现在已经构建好了。运行该程序有效,我可以重新检查项目属性中的“保存时编译”框。
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.
我通过从现有来源创建一个新的 netbeans 项目解决了我的问题。在我看来,这不是一个好方法(尤其是在大型项目中),但现有的答案都没有提供解决方案。
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.
这类问题几乎总是由类路径问题引起的。
These kinds of problems are almost always due to classpath issues.
尝试删除 .cache 文件夹,它对我有用。例如在我的机器中,netbeans的缓存文件夹位于/home/chieuvh/.cache/netbeans/15
Try remove the .cache folder, it worked for me. For example in my machine, cache folder of netbeans is located at /home/chieuvh/.cache/netbeans/15