Search code examples
javanetbeansmethodsprogram-entry-pointnetbeans-8

Setting the Main Class and main() method in Netbeans IDE


Frustrated with Netbeans!!

I have created a Project with four classes. Now I want to run the main() method of the Main class. How do i do it. There is no other main() method in the whole package.

Note: There are more than one methods in the Main Class(including main()).

Here is my Project Structure.

So What do i do??

And this written in Projects Properties--->Run--->computer.project.netbeans.ComputerProjectNetbeans (Screenshot is Here)

And Here is My code Sample of my Main class:

class Main
{
    void Main()
    {
         \\Code
    }
    void A()
    {
         \\Code
    }
    void B()
    {
         \\Code
    }
    void C()
    {
         \\Code
    }
}

Solution

  • You need to add a public static void main(String[] args){} method in which you will create an instance of your Main class in order for NetBeans to recognize "where" to start and begin executing your code. You can place the main method in the same class, after all your methods.

    Added code

    public static void main(String[] args) {
        Main main = new Main();
        //Additional code
    }