错误“未找到主类”
所有,
我的类路径已设置为以下文件夹:
CLASSPATH = .;C:\Program Files\Java\jdk1.6.0_21\bin;C:\Program Files\Java\jdk1.6.0_21\bin\project
我的所有java文件和类文件都在CLASSPATH
中列出的project
文件夹下。
然而,我在 project
文件夹中运行 DriverClass
时收到以下错误:
C:\Program Files\Java\jdk1.6.0_21\bin\project>java DriverClass
Exception in thread "main" java.lang.NoClassDefFoundError: DriverClass (wrong name: project/DriverClass)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: DriverClass. Program will exit.
任何人都可以帮我理解这里的原因吗?
All,
My classpath has been set to the following folder:
CLASSPATH = .;C:\Program Files\Java\jdk1.6.0_21\bin;C:\Program Files\Java\jdk1.6.0_21\bin\project
All my java files and class files are under project
folder listed in CLASSPATH
.
Yet I am getting the following error while running a DriverClass
in project
folder:
C:\Program Files\Java\jdk1.6.0_21\bin\project>java DriverClass
Exception in thread "main" java.lang.NoClassDefFoundError: DriverClass (wrong name: project/DriverClass)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: DriverClass. Program will exit.
Can anyone please help me understand the reason here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你在包裹里。您应该位于包根目录中。向上移动一个文件夹。
然后使用
java project.DriverClass
重新执行它。也就是说,您应该不喜欢使用 CLASSPATH 环境变量。您的目前也无效。未加引号的路径名中有空格。此外,
JDK/bin
文件夹不应该位于类路径中。只需使用-cp
参数,例如java -cp 。 project.DriverClass
(位于包根文件夹中)。You're inside the package. You should be sitting in the package root. Go one folder up.
Then reexecute it using
java project.DriverClass
.That said, you should prefer not to use the
CLASSPATH
environment variable. Yours is currently also invalid. There are spaces in unquoted pathnames. Also, theJDK/bin
folder isn't supposed to go in the classpath. Just use the-cp
argument likejava -cp . project.DriverClass
(while sitting in the package root folder).尝试:
假设您的包是
project
Try:
assuming your package is
project
编译后,如果我们收到主类未找到错误,很简单,试试这个
设置类路径=%classpath%;.;
在cmd中输入并运行它..问题将得到解决
After compiling if we get a main class not found error, It is simple try this
set classpath=%classpath%;.;
type this in cmd and run it..problem will be resolved