No Main class found in NetBeans

前端 未结 16 2443
时光说笑
时光说笑 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:28

    I also experienced Netbeans complaining to me about "No main classes found". The issue was on a project I knew worked in the past, but failed when I tried it on another pc.

    My specific failure reasons probably differ from the OP, but I'll still share what I learnt on the debugging journey, in-case these insights help anybody figure out their own unique issues relating to this topic.

    What I learnt is that upon starting NetBeans, it should perform a step called "Scanning projects..."

    Prior to this phase, you should notice that any .java file you have with a main() method within it will show up in the 'Projects' pane with its icon looking like this (no arrow):

    After this scanning phase finishes, if a main() method was discovered within the file, that file's icon will change to this (with arrow):

    So on my system, it appeared this "Scanning projects..." step was failing, and instead would be stuck on an "Opening Projects" step.

    I also noticed a little red icon in the bottom-right corner which hinted at the issue ailing me:

    Unexpected Exception
    java.lang.ExceptionInInitializerError
    

    Clicking on that link showed me more details of the error:

    java.security.NoSuchAlgorithmException: MD5 MessageDigest not available
        at sun.security.jca.GetInstance.getInstance(GetInstance.java:159)
        at java.security.Security.getImpl(Security.java:695)
        at java.security.MessageDigest.getInstance(MessageDigest.java:167)
        at org.apache.lucene.store.FSDirectory.<clinit>(FSDirectory.java:113)
    Caused: java.lang.RuntimeException
        at org.apache.lucene.store.FSDirectory.<clinit>(FSDirectory.java:115)
    Caused: java.lang.ExceptionInInitializerError
        at org.netbeans.modules.parsing.lucene.LuceneIndex$DirCache.createFSDirectory(LuceneIndex.java:839)
    

    That mention of "java.security" reminded me that I had fiddled with this machine's "java.security" file (to be specific, I was performing Salvador Valencia's steps from this thread, but did it incorrectly and broke "java.security" in the process :))

    Once I repaired the damage I caused to my "java.security" file, NetBeans' "Scanning projects..." step started to work again, the little green arrows appeared on my files once more and I no longer got that "No main classes found" issue.

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

    The connections I made in preparing this for posting really cleared it up for me, once and for all. It's not completely obvious what goes in the Main Class: box until you see the connections. (Note that the class containing the main method need not necessarily be named Main but the main method can have no other name.)

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

    You need to rename your main class to Main, it cannot be anything else.

    It does not matter how many files as packages and classes you create, you must name your main class Main.

    That's all.

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

    In the toolbar search for press the arrow and select Customize... It will open project properties.In the categories select RUN. Look for Main Class. Clear all the Main Class character and type your class name. Click on OK. And run again. The problem is solved.

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