Reputation: 11
The error states Error main method not found in class
. Please define the main method as:
public static void main(String[] args)
.
Eclipse was working for me a few days ago, but now it just gives me that message
an example would be
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World");
}
}
Upvotes: 1
Views: 23183
Reputation: 11
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.
Upvotes: 1
Reputation: 11
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.
Upvotes: 0
Reputation: 1271
I ran into the same issue. Just clean your project..save your project and then run it.
Upvotes: 1
Reputation: 1
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.
Upvotes: 0
Reputation: 131
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".
Upvotes: 3
Reputation: 12242
First clean your project Using Project-->Clean
and then build it again.
Also make sure that your build path is properly set.
Upvotes: 1