javaeclipseprojectstartupstartup-error

Error: Selection does not contain a main type


I am trying to run some java files in a new project. So I make the project, put the files in it and I try to run the main file so my game starts.

I get an error that says selection does not contain a main type.

I have tried several ways to run it:

Didn't work either.

I am pretty sure it must work because I ran it a few hours ago at school. How do I get this working? Thank you in advance!


Solution

  • I hope you are trying to run the main class in this way, see screenshot:
    screenshot of Eclipse file context menu

    If not, then try this way. If yes, then please make sure that your class you are trying to run has a main method, that is, the same method definition as below:

    public static void main(String[] args) {
        // some code here
    }
    

    I hope this will help you.