Eclipse: How to set the main method for a project?

In Eclipse, when you create a new class, you can choose the option “What stub methods you would like to create:” and you can choose “ public static void main (String args []) ”.

I created a class with the main method, but I did not check this option, and I get this error: " selection does not contain the main type in eclipse ". How can I show Eclipse that I have the main method in the class without deleting / re-creating the class file?

Later Edit: :) Guilty: My main method is as follows: public static void main (String args) , and because of this I got an error.

+3
source share
2 answers

I suspect that the signature of your method is incorrect. It must be exactly:

public static void main(String[])

otherwise it will not work. The method naming Mainwill fail, and the method argument will not be denied. In addition, I think the class should be publicly available.

+2
source

Are you sure you have a method like public static void main(String[] args)

You should check for typos in your code. Perhaps you could post an example of your main method.

0
source

Source: https://habr.com/ru/post/1723086/


All Articles