Main method not found even if I've declared it

后端 未结 7 1747
感动是毒
感动是毒 2020-11-27 07:31

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

Error: Main method not found in class

7条回答
  •  無奈伤痛
    2020-11-27 07:57

    If the answers above are not working for you: make sure "main" is not capitalized in your method definition.

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

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

    Though the error message makes the required syntax for the main method clear, incorrect caps can be hard to spot. It took me ~30 minutes of troubleshooting to find this typo today. This was clearly not an issue for the OP, but is another easy/likely way to produce the same error message, and this answer may help other users.

提交回复
热议问题