黑马程序员技术交流社区

标题: 执行javac时,提示could not find the main class program will exit [打印本页]

作者: yesecongcong    时间: 2014-8-2 15:21
标题: 执行javac时,提示could not find the main class program will exit
首先Eclipse能正常运行程序
命令行窗口执行java 123.java 命令也能生成class 文件,但是执行java 123时就提示:
Exception in Thread "main" java.lang.NoClassDefFoundError:123
Caused by: java.lang.ClassNotFoundException: 123
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: 123.  Program will exit.

环境变量已经配置了,javahome=C:\Program Files (x86)\Java\jdk1.6.0_10\
                              path=.;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files (x86)\Common Files\Adobe\AGL;%java_home%\bin;%java_home%\jre\bin
%java_home%\jre\bin
                           classpath=.;%java_home%lib;%java_home%\lib\tools.jar

各种百度,也没弄明白,想卸载了重新安装,但是还是想搞明白这是怎么回事,大神给讲解讲解


作者: 王松朝    时间: 2014-8-3 15:24
首先,请先去查一查java的命名规范,其次,需要贴出你的代码,而不是系统变量,再次,请确保你的类里有main函数且符合java规范!!!!!!!!!!!
作者: 地狱天堂    时间: 2014-8-3 15:45
本帖最后由 地狱天堂 于 2014-8-3 16:00 编辑

类名不能以数字开头。
你的类名跟文件名不相同。把文件名改成类名即可。






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2