错误:无法在 Eclipse 中找到或加载主类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12445625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Could not find or load main class in Eclipse
提问by Zach Latta
I'm having trouble running a project in Eclipse 4.2. I have a Java program with one class titled Conversion. Eclipse builds the project fine. I'm able to run the program from the command line by navigating to /bin/ in the project's folder that's in the workspace and typing java Conversion
.
我在 Eclipse 4.2 中运行项目时遇到问题。我有一个 Java 程序,其中包含一个名为 Conversion 的类。Eclipse 可以很好地构建项目。我可以通过导航到工作区中项目文件夹中的 /bin/ 并键入java Conversion
.
However, when I try to run the program from Eclipse, I am shown Error: Could not find or load main class Conversion
in the console.
但是,当我尝试从 Eclipse 运行该程序时,我会显示Error: Could not find or load main class Conversion
在控制台中。
The project name is 10.12.12: Project
.
项目名称是10.12.12: Project
.
采纳答案by Zach Latta
Eclipse does not support the use of a colon or hyphen in project names. Colons appear to break the way it handles compilation.
Eclipse 不支持在项目名称中使用冒号或连字符。冒号似乎打破了它处理编译的方式。
The issue can be fixed by not using a colon in the project's name.
该问题可以通过不在项目名称中使用冒号来解决。
As noted in the comments, this may be a fault of Java 6. It is fixed in Java 7.
如评论中所述,这可能是 Java 6 的错误。它在 Java 7 中已修复。
回答by Cratylus
It appears that the project is not part of the classpath.
Check in your Run Configuration->Classpath
and if your project is not there, then add it under User Entries
.
该项目似乎不是类路径的一部分。
检查Run Configuration->Classpath
您的项目,如果您的项目不存在,则将其添加到User Entries
.
回答by rizwan
Make sure the build path is configured properly in the eclipse. Paths for the external JAR files may be wrong.
确保在 eclipse 中正确配置了构建路径。外部 JAR 文件的路径可能有误。
回答by FederOnline
I understand the ':' was likely the case here, but I had a tangential issue that might help someone else.
我理解 ':' 可能是这里的情况,但我有一个可能对其他人有帮助的切线问题。
I inherited a project and was having a similar issue. Dev/Debugging is on Mac/Win, and the TST/UAT/PRD environment is RHEL. Someone literally copied the systemd command line and left a '\' in the Debug arguments. The reason this was hard to find is that the lines wrap right at the -D, so the \ is the last char on a line, which looks OK under Linux. I fixed it like this...
我继承了一个项目并且遇到了类似的问题。Dev/Debugging在Mac/Win上,TST/UAT/PRD环境是RHEL。有人从字面上复制了 systemd 命令行,并在 Debug 参数中留下了一个“\”。很难找到的原因是这些行在 -D 处自动换行,所以 \ 是一行中的最后一个字符,在 Linux 下看起来不错。我是这样修的...
In my case it was...
就我而言,它是...
-Dlog4j.configurationFile=file:<PATH>/log4j2.xml \
-DCONFIG_PATH=...
Right-Click Project -> Run-As/Debug-As, click the Arguments Tab.
In the VM Arguments, look for \.
HTH.
哈。
回答by Veerendar Chary Munigadapa
This Problem will accrues Saving file name one name and compile time u have gives another name. That time you will get that problem. Check the java file name once.
这个问题将累积保存文件名一个名称和编译时间你给出另一个名称。到时候你就会遇到那个问题。检查一次 java 文件名。