Q.Ali
Q.Ali

Reputation: 67

Eclipse not finding a main method

Firstly, I know that similar questions have been asked and answered before, however none of the solutions worked in my case. For some reason, eclipse keeps showing a launch error saying that no main method is found despite there being a public static void main(String[] args) in my main class. Could there be an issue in the class path? I'm really unsure whats causing it.Here is a screenshot of eclipse with the main method

Upvotes: 1

Views: 4851

Answers (4)

Mariqn Marinov
Mariqn Marinov

Reputation: 23

I got the same error but with different reason. I changed my java build path libraries to 15.0.1 and tried to run and it failed after that I changed them back to 11.0.2 and it worked.

Upvotes: 0

user8906405
user8906405

Reputation: 21

Go to Run->Run Configurations, select your project. In the Main tab, for Main class, give class name along with complete path of the class containing main function. This worked for me :)

Upvotes: 2

Cronical
Cronical

Reputation: 34

Try to say at the beginning of the code:

package yourpackage; //<----------your package is the name of the package you are in

The class havent automatically put the package comment at the beginning of the Code because like the other say your structure is false.

Yours:

project -----> classes,src

Should be:

project ---->src ---->package----> class

Upvotes: 0

Luis Miguel Serrano
Luis Miguel Serrano

Reputation: 5099

Try putting your java files under the "src" folder. Apparently they are all out of that folder and that could be the cause.

Upvotes: 2

Related Questions