Netbeans - class does not have a main method

后端 未结 12 2640
别跟我提以往
别跟我提以往 2020-12-06 14:28

My program is just a simple System.out.println(\"\"); But netbeans cannot find the main method. Is netbeans 6.7.1 conflict with WIN7? Any possible error?

12条回答
  •  星月不相逢
    2020-12-06 15:24

    I had this issue as well (Error: Could not find or load main class test.Test). I'll explain this relatively basically since I know I would have appreciated someone doing that when I was looking for my answer.

    When I right-clicked on the project (left hand side of the screen unless you got rid of the projects tab) and went to properties and then run, the main class had the projectname.classname, which is what confused me. For example, I created a project "test" to test this out, and when I went to

    (right-click) test or Source Packages -> properties -> run -> main class

    had Test.test in that field, which is what the problem was. the class is test, not Test.test, so I clicked browse to its right, and the only thing in the list to select from was test, and when I selected that and tried rerunning it, it finally worked.

    Additionally, I found that when you create a new project in Netbeans, one of the things it originally gives you (in my case of the project named test) is package test;. If you are having this problem, then like me, you probably originally got rid of that line seeing it as just another line of code you didn't need. That line of code is what enabled your main class which in my case was Test.test to find the main class *test from that.

提交回复
热议问题