1

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");
    }
}
Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
Applesire Jon
  • 11
  • 1
  • 1
  • 4
  • 1
    Then why don't you do as it says? Define the `main()` as `public static void main(String[] args)`. – Rahul Oct 29 '13 at 04:56
  • 1
    Show us some code that doesn't work, and we'll tell you why. I'm assuming that it's not something obvious, like incorrectly spelling `main` with a capital M, or omitting the square brackets. – Dawood ibn Kareem Oct 29 '13 at 04:58
  • If that doesn't work, let's see your whole class with the main method please. – sdanzig Oct 29 '13 at 04:59
  • 1
    Try cleaning your project and re-build. – Juned Ahsan Oct 29 '13 at 05:02
  • Probably the name of file is not matching the class name. – mtk Oct 29 '13 at 06:53
  • Sometimes we forget to save the current file and try to run that. I just ran into the same problem due to this reason so adding this comment despite so late. Check if you also made the same mistake (forget to save Test class with Ctrl+s). – Manishoaham Jun 02 '19 at 15:11

7 Answers7

3

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".

Plinio FM
  • 131
  • 1
  • 5
1

First clean your project Using Project-->Clean and then build it again.

Also make sure that your build path is properly set.

Prateek
  • 12,014
  • 12
  • 60
  • 81
1

I ran into the same issue. Just clean your project..save your project and then run it.

user3681970
  • 1,201
  • 4
  • 19
  • 37
1

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.

user5219763
  • 1,284
  • 12
  • 19
adii00786
  • 11
  • 2
0

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.

0

Try to resturt Eclipse in a new workspace.

Smith
  • 1
0

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.

adii00786
  • 11
  • 2