I have a very simple code:
package mygame;
public class RunGame {
public static void main(String[] args) {
System.out.println(args[0]);
}
}
I can compile that code but I cannot run it. When I type "java RunGame" in the command line I get:
Exception in thread "main" java.lang.NoClassDefFoundError: RunGame (wrong name: mygame/RunGame).
....
Could not find the main class: RunGame. Program will exit.
To change the main class being used, go to the File menu and choose Project Properties. This dialog gives all the options that can be changed in a NetBeans project. Click on the Run category. On this page, there is a Main-Class option.
The Java Main ClassIf only a single Java class in your Java program contains a main() method, then the class containing the main() method is often referred to as the main class. You can have as many classes as you want in your project with a main() method in.
When the JVM is unable to locate the main class, it's often because it's looking for the corresponding . class files in the wrong classpath. Of course, the way to rectify this problem is to manually specify the classpath by either using packages or specifying the classpath.
java mygame.RunGame
is the java executable syntax. i.e, java classname.qualified.with.full.packaging
Also what is the RunColoredTrails class in the output you have shown?
u might be tryingC:\your-java-directory-\mydir\> java RunGame
right ?
remember RunGame is inside a package called mydir. so go one step back in ur execution path..
c:\your-java-directory\>
now compile and execute like this
c:\your-java-directory\> javac mydir\RunGame.java
c:\your-java-directory\> java mydir.RunGame
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With