Why it could not find the main class?

穿精又带淫゛_ 提交于 2020-01-01 09:04:43

问题


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.


回答1:


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?




回答2:


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



来源:https://stackoverflow.com/questions/2416750/why-it-could-not-find-the-main-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!