Netbeans - class does not have a main method

后端 未结 12 2624
别跟我提以往
别跟我提以往 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:23

    If you named your class with the keyword in Java, your program wouldn't be recognized that it had the main method.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-06 15:29

    Exceute the program by pressing SHIFT+F6, instead of clicking the RUN button on the window. This might be silly, bt the error main class not found is not occurring, the project is executing well...

    0 讨论(0)
  • 2020-12-06 15:30

    in Project window right click on your project and select properties go to Run and set Main Class ( you can brows it) . this manual work if you have static main in some class :

    public class Someclass
    {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args)
        {
            //your code
        }
    }
    

    Netbeans doesn't have any conflict with W7 and you can use version 6.8 .

    0 讨论(0)
  • 2020-12-06 15:32

    Sometimes passing parameters in the main method causes this problem eg. public static void main(String[] args,int a). If you declare the variable outside the main method, it might help :)

    0 讨论(0)
  • 2020-12-06 15:33

    This happens when you move your main class location manually because Netbeans doesn't refresh one of its property files. Open nbproject/project.properties and change the value of main.class to the correct package location.

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