为什么找不到主类?
我有一个非常简单的代码:
package mygame;
public class RunGame {
public static void main(String[] args) {
System.out.println(args[0]);
}
}
我可以编译该代码,但无法运行它。当我在命令行中输入“java RunGame”时,我得到:
线程“main”中出现异常 java.lang.NoClassDefFoundError: RunGame(错误名称:mygame/RunGame)。
....
找不到主类: 运行游戏。程序将退出。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是java可执行语法。即, java classname.qualified.with.full.packaging
另外,您显示的输出中的 RunColoredTrails 类是什么?
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?
你可能正在尝试
C:\your-java-directory-\mydir\> java RunGame 对吗?
请记住 RunGame 位于名为 mydir 的包内。
所以在你的执行路径中后退一步..
c:\your-java-directory\>
现在像这样编译和执行
c:\your-java-directory\> javac mydir\RunGame.java
c:\your-java-directory>> java mydir.RunGame
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