The main method was not found, even if I declared it

I want to create a simple java class with the main method, but when I compile my code, I get this error message:

Error: the main method was not found in the errors of the .TestErrors class, please define the main method: public static void main (String [] args)

This is the source code:

package errors;

public class TestErrors {
    public static void main(String[] args){
        System.out.println("hello");
    }
}

Why am I seeing this error, as you may notice that alreader has declared the main method!

+6
source share
6 answers

As stated in my comments, it looks like you declared a class Stringamong your own classes. To prove this, I created a basic example:

class String {
}

public class CarelessMain {
    public static void main(String[] args) {
        System.out.println("won't get printed");
    }
    public static void main(java.lang.String[] args) {
        System.out.println("worked");
    }
}

, "worked" . main, ( ):

: edu.home.poc.component.CarelessMain, , :

public static void main(String[] args)
+19

, IDE , (.. ) , , IDE ,

, -, , , ,

+3

Java , . java .

+1

: , "" .

OK: public static void main(String[] args)

ERROR: public static void Main(String[] args)

, . 30 , . OP, / , .

0

( ) → Run As- > Run Configurations- > " "

"".

-1

.

//package errors;
-1

All Articles