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:
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). Af开发者_如何学Goter 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 :(
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.
精彩评论