“Error: Main method not found in class MyClass, please define the main method as…”

前端 未结 8 1056
南旧
南旧 2020-11-22 01:15

New Java programmers often encounter these messages when they attempt to run a Java program.


Error: Main met         


        
8条回答
  •  自闭症患者
    2020-11-22 01:54

    If you are running the correct class and the main is properly defined, also check if you have a class called String defined in the same package. This definition of String class will be considered and since it doesn't confirm to main(java.lang.String[] args), you will get the same exception.

    • It's not a compile time error since compiler just assumes you are defining a custom main method.

    Suggestion is to never hide library java classes in your package.

提交回复
热议问题