No Main class found in NetBeans

前端 未结 16 2442
时光说笑
时光说笑 2020-11-30 08:32

I have been working on an assignment for my class in programming. I am working with NetBeans. I finished my project and it worked fine. I am getting a message that says \"No

相关标签:
16条回答
  • 2020-11-30 09:07

    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:

    1. Create new project - Maven - Java application (project created: mytest; package created: com.me.test)
    2. Right-click package: com.me.test
    3. New > Java Class > Named it 'Whatever' you want
    4. Right-click package: com.me.test
    5. New > Java Main Class > named it: 'Main' (must be 'Main')
    6. Right click on Project mytest
    7. Click on Properties
    8. Click on Run > next to 'Main Class' text box: > Browse
    9. You should see: com.me.test.Main
    10. Select it and click "Select Main Class"

    Hope this works for others as well.

    0 讨论(0)
  • 2020-11-30 09:08

    You need to add }} to the end of your code.

    0 讨论(0)
  • 2020-11-30 09:11

    In project properties, under the run tab, specify your main class. Moreover, To avoid this issue, you need to check "Create main class" during creating new project. Specifying main class in properties should always work, but if in some rare case it doesn't work, then the issue could be resolved by re-creating the project and not forgetting to check "Create main class" if it is unchecked.

    0 讨论(0)
  • 2020-11-30 09:13

    Press the hammer to the left of the green arrow (run), for the program to clean & build project. Press green arrow. Select Main Class.

    Hope it works for u.

    0 讨论(0)
  • 2020-11-30 09:14

    Make sure the access modifier is public and not private. I keep having this problem and always that's my issue.

    public static void main(String[] args)

    0 讨论(0)
  • 2020-11-30 09:15

    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/

    0 讨论(0)
提交回复
热议问题