[英]NoClassDefFoundError on Netbeans but runs on command line
I am trying to run a hello world java program on Netbeans but its giving me the following error:我正在尝试在 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)
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).
然后,我回到 Netbeans 并再次运行它。这次它成功了(因为 HelloWorld.class 文件位于 src 文件夹下)。 After deleting the.class file from the folder, it did not run again on Netbeans.
从文件夹中删除 .class 文件后,它没有在 Netbeans 上再次运行。
It is something to do with Netbeans but I can't seem to figure out what would fix this issue.这与 Netbeans 有关,但我似乎无法弄清楚什么可以解决这个问题。 I checked under project properties -> Libraries -> and the java platform is set to JDK 1.6
我在项目属性 -> 库 -> 下检查了 java 平台设置为 JDK 1.6
I am using Netbeans 7.0 on Mac.我在 Mac 上使用 Netbeans 7.0。
Please help me out:(请帮帮我:(
NetBeans is running.class file not.jar when you run project. NetBeans 正在运行。class 文件不是。jar 运行项目时。 Usually it runs.class from build/classes directory.
通常它从 build/classes 目录运行.class。 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 .
这是如何在 NetBeans 中创建和运行 Hello World 应用程序的详细教程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.