简体   繁体   中英

Why it could not find the main class?

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.

java mygame.RunGame 

is the java executable syntax. ie, java classname.qualified.with.full.packaging

Also what is the RunColoredTrails class in the output you have shown?

u might be trying
C:\\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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM