No Main class found in NetBeans
Solution 1:
- Right click on your Project in the project explorer
- Click on properties
- Click on Run
- Make sure your Main Class is the one you want to be the entry point. (Make sure to use the fully qualified name i.e. mypackage.MyClass)
- Click OK.
- Run Project :)
If you just want to run the file, right click on the class from the package explorer, and click Run File, or (Alt + R, F), or (Shift + F6)
Solution 2:
Also, for others out there with a slightly different problem where Netbeans will not find the class when you want when doing a browse from "main classes dialog window".
It could be that your main method does have the proper signature. In my case I forgot the args.
example: public static void main(String[] args)
The modifiers public and static can be written in either order (public static or static public), but the convention is to use public static as shown above.
Args: You can name the argument anything you want, but most programmers choose "args" or "argv".
Read more here: http://docs.oracle.com/javase/tutorial/getStarted/application/
Solution 3:
When creating a new project - Maven - Java application in Netbeans the IDE is not recognizing the Main class on 1st class entry. (in Step 8 below we see no classes).
When first a generic class is created and then the Main class is created Netbeans is registering the Main class and the app could be run and debugged.
Steps that worked for me:
- Create new project - Maven - Java application (project created: mytest; package created: com.me.test)
- Right-click package: com.me.test
- New > Java Class > Named it 'Whatever' you want
- Right-click package: com.me.test
- New > Java Main Class > named it: 'Main' (must be 'Main')
- Right click on Project mytest
- Click on Properties
- Click on Run > next to 'Main Class' text box: > Browse
- You should see: com.me.test.Main
- Select it and click "Select Main Class"
Hope this works for others as well.
Solution 4:
I had the same problem in Eclipse, so maybe what I did to resolve it can help you. In the project properties I had to set the launch configurations to the file that contains the main-method (I don't know why it wasn't set to the right file automatically).