在类中找不到 Java Eclipse 错误方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19649949/
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
Java Eclipse error method not found in class
提问by Applesire Jon
The error states Error main method not found in class
. Please define the main method as:
public static void main(String[] args)
.
错误状态Error main method not found in class
。请将主要方法定义为:
public static void main(String[] args)
。
Eclipse was working for me a few days ago, but now it just gives me that message
几天前 Eclipse 为我工作,但现在它只是给了我这样的信息
an example would be
一个例子是
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World");
}
}
回答by Prateek
First clean your project Using Project-->Clean
and then build it again.
首先清理您的项目Project-->Clean
,然后再次构建它。
Also make sure that your build path is properly set.
还要确保您的构建路径设置正确。
回答by Plinio FM
Check if exists any error in your project. Not just the compilation errors. Click on project and check the "Problems" view in Eclipse. You need to remove all of "Errors".
检查您的项目中是否存在任何错误。不仅仅是编译错误。单击项目并检查 Eclipse 中的“问题”视图。您需要删除所有“错误”。
回答by galactiger
I ran into this problem also when I moved the location of the main method in my program to another file in the same program. If this is what happened to you, the fix is to go to the top of Eclipse near the bug and play icons and change the "Run as..." field to "Java application" from whatever its previous location was.
当我将程序中 main 方法的位置移动到同一程序中的另一个文件时,我也遇到了这个问题。如果您遇到这种情况,修复方法是转到 Eclipse 顶部靠近 bug 并播放图标,并将“运行方式...”字段从其先前位置更改为“Java 应用程序”。
回答by Smith
Try to resturt Eclipse in a new workspace.
尝试在新工作区中恢复 Eclipse。
回答by user3681970
I ran into the same issue. Just clean your project..save your project and then run it.
我遇到了同样的问题。只需清理您的项目...保存您的项目,然后运行它。
回答by adii00786
Check whether you have created a class with the name "String". If you have created a class with the name "String", the compiler will not be able to resolve the conflict between 2 classes i.e. java.lang.String
and your String
class therefore it won't recognize the main method.
So just remove that String class or rename it.It happened to me also.. I resolved using this only.
检查您是否创建了名为“String”的类。如果您创建了一个名为“String”的类,编译器将无法解决 2 个类之间的冲突,即java.lang.String
与您的String
类之间的冲突,因此它将无法识别 main 方法。所以只需删除该 String 类或重命名它。它也发生在我身上。我只解决了使用它。
回答by adii00786
Maybe you are creating 2 classes in the same package or u have defined one of your defined class name as "String". If you have then change that classname to something else , because at that time compiler cannot differentiate between java.lang.String and your user defined class "String". So jst chage the name of that String class.
也许您正在同一个包中创建 2 个类,或者您已将定义的类名之一定义为“字符串”。如果您已经将该类名更改为其他名称,因为那时编译器无法区分 java.lang.String 和您用户定义的类“String”。因此,请更改该 String 类的名称。