简体   繁体   English

Eclipse 找不到主要方法

[英]Eclipse not finding a main method

Firstly, I know that similar questions have been asked and answered before, however none of the solutions worked in my case.首先,我知道之前已经问过并回答过类似的问题,但是没有一个解决方案适用于我的情况。 For some reason, eclipse keeps showing a launch error saying that no main method is found despite there being a public static void main(String[] args) in my main class.出于某种原因,eclipse 一直显示启动错误,指出尽管我的主类中有一个 public static void main(String[] args) ,但没有找到 main 方法。 Could there be an issue in the class path?类路径中可能存在问题吗? I'm really unsure whats causing it.我真的不确定是什么原因造成的。这是带有main方法的eclipse截图

Try putting your java files under the "src" folder.尝试将您的 java 文件放在“src”文件夹下。 Apparently they are all out of that folder and that could be the cause.显然他们都在那个文件夹之外,这可能是原因。

Go to Run->Run Configurations, select your project.转到运行->运行配置,选择您的项目。 In the Main tab, for Main class, give class name along with complete path of the class containing main function.在 Main 选项卡中,对于 Main 类,给出类名以及包含 main 函数的类的完整路径。 This worked for me :)这对我有用:)

Try to say at the beginning of the code:试着在代码开头说:

package yourpackage;打包你的包裹; //<----------your package is the name of the package you are in //<----------your package 是你所在的包名

The class havent automatically put the package comment at the beginning of the Code because like the other say your structure is false.该类没有自动将包注释放在代码的开头,因为像其他人一样说您的结构是错误的。

Yours:你的:

project -----> classes,src项目 -----> 类,src

Should be:应该:

project ---->src ---->package----> class项目---->src---->包---->类

I got the same error but with different reason.我遇到了同样的错误,但原因不同。 I changed my java build path libraries to 15.0.1 and tried to run and it failed after that I changed them back to 11.0.2 and it worked.我将我的 java 构建路径库更改为 15.0.1 并尝试运行,但在我将它们更改回 11.0.2 之后它失败了并且它起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM