If the main method cannot be found in java, an error will suddenly occur, and the cause is unknown.

I'm currently using Eclipse
Package name exception
The class name is used in Main.java.

I made the following description in Main.java.

package exception;
public class Main {
     public static void main (String [] args) {
         System.out.println ("Why");

In this state, when I executed the java application with Main.java,
You will get an error like this.

Error: The main method cannot be found in class exception.Main. Define the main method as follows:
public static void main (String [] args)
Or the JavaFX application class needs to extend javafx.application.Application

I'm confused because I don't know the cause.
What is the cause of this error even though I have defined the Main method?

We apologize for the basic question, but thanks for your understanding.

  • Answer # 1

    It looks like the code isn't inconvenient.

    Why not save the code and try running it again?

    package declaration | Introduction to Java code

    Also, the location where the class is saved must correspond to the package hierarchy. Classes belonging to the com.example.mynavi.object package must be saved in the/com/example/mynavi/object folder.

    Is it okay here?