错误“未找到主要类别” [英] Error "main class not found"

查看:130
本文介绍了错误“未找到主要类别”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部,

我的类路径已设置为以下文件夹:

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

我所有的java文件和类文件都在项目下 CLASSPATH 中列出的文件夹。

All my java files and class files are under project folder listed in CLASSPATH.

但运行 DriverClass时出现以下错误 in project 文件夹:

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?

推荐答案

你在包里面。你应该坐在包根目录中。去一个文件夹。

You're inside the package. You should be sitting in the package root. Go one folder up.

cd ..

然后使用 java project.DriverClass 重新执行它。

也就是说,你不应该使用 CLASSPATH 环境变量。你的目前也是无效的。未加引号的路径名中有空格。此外, JDK / bin 文件夹不应该在类路径中。只需使用 -cp 参数,如 java -cp。 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, the JDK/bin folder isn't supposed to go in the classpath. Just use the -cp argument like java -cp . project.DriverClass (while sitting in the package root folder).

这篇关于错误“未找到主要类别”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆