开发者

trying to follow along with simple Java tutorial, NetBeans not compiling code [closed]

开发者 https://www.devze.com 2023-01-27 07:13 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号