Netbeans 上出现 NoClassDefFoundError 但在命令行上运行
我正在尝试在 Netbeans 上运行 hello world java 程序,但它给了我以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
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)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
我在命令行上编译并运行了它,它工作了。然后,我回到 Netbeans 并再次运行它..这次它起作用了(因为 HelloWorld.class 文件位于 src 文件夹下)。从文件夹中删除 .class 文件后,它不再在 Netbeans 上运行。
这与 Netbeans 有关,但我似乎不知道如何解决这个问题。我在项目属性下检查了 ->图书馆 ->并且java平台设置为JDK 1.6
我在Mac上使用Netbeans 7.0。
请帮帮我:(
I am trying to run a hello world java program on Netbeans but its giving me the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
Caused by: java.lang.ClassNotFoundException: HelloWorld
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)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
I compiled and ran it on Command line and it worked. Then, I went back to Netbeans and I ran it again..this time it worked (because HelloWorld.class file is under the src folder). After deleting the .class file from the folder, it did not run again on Netbeans.
It is something to do with Netbeans but I can't seem to figure out what would fix this issue. I checked under project properties -> Libraries -> and the java platform is set to JDK 1.6
I am using Netbeans 7.0 on Mac.
Please help me out :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
运行项目时,NetBeans 正在运行 .class 文件而不是 .jar。通常它从 build/classes 目录运行 .class。如果您提供项目结构的描述(甚至屏幕截图),我们可以告诉您更多信息。 这里是如何在 NetBeans 中创建和运行 Hello World 应用程序的详细教程。
NetBeans is running .class file not .jar when you run project. Usually it runs .class from build/classes directory. If you provide description of your project structure (or even screenshod) we could tell more. Here is detailed tutorial how to create and run Hello World app in NetBeans.