I'm using NetBeans 6.9.1 on windows and i am following along with a rather simple java tutorial, first it asks me to use notepad but i'd rather just use a IDE for this, anyways i'm asked to create a file and put this code down:
class HelloWorldApp {
public static void main(String[ ] args) {
System.out.println("Hello World!" );
}
}
and i get a lot of compiler errors:
java.lang.NoClassDefFoundError: javaapplication1/Main
Caused by: java.lang.ClassNotFoundException: javaapplication1.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.ne开发者_如何学Pythont.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)
Could not find the main class: javaapplication1.Main. Program will exit.
Exception in thread "main" Java Result: 1
i tried to get the wizard to make as clean a starting project as possible, but it seems that nothing is simple here.
so is the code wrong, and the tutorial thus not worth following, or am i doing something wrong with the IDE?
your compiler is looking for a Class
called Main
in a package
called javaapplication1
.
What you posted doesn't fit this at all.
Classes must be in a file with the name of the class.java
.
Thus your class should be in a file called HelloWorldApp.java
in the default
package.
From your stack trace this is not the case and appears to be in a file called Main.java
in a package
called javaaplication1
Is it saying that it's trying to find a class named Main but you've named the class HelloWorldApp?
Is the HelloWorldApp in a file called HelloWorldApp.java?
Is your file named HelloWorldApp.java?
精彩评论