Search code examples
javanetbeansprogram-entry-point

How do I fix "<No main class found>"?


I am trying to run some Java code in NetBeans and it keeps telling me that there is no main class. I have looked at other similar questions but they don't help in fixing my particular problem.

Even when I add the main loop it still tells me there is no main class. The purpose of this code is to create a class called VolcanoRobot which can be used in another program, or I could add the public static void main(String args[]) and just run this code.

Trying both methods the compiler still has this same issue. Here is the code I have for using the class:

class VolcanoApplication {
     public static void main(String[] args ){
     VolcanoRobot dante = new VolcanoRobot();
     dante.status = "exploring";
     dante.speed = 2;
     dante.temperature = 510;

     dante.showAttributes();
     System.out.println("Increasing speed to 3.");
     dante.speed = 3;
     dante.showAttributes();
     System.out.println("Changing temperature to 670.");
     dante.temperature = 670;
     dante.showAttributes();
     System.out.println("Checking the temparature");
     dante.checkTemperature();
     dante.showAttributes();


}}

Creation of VolcanoRobot:

    class  VolcanoRobot {
        String status;
        int speed;
        float temperature;

        void checkTemperature() {
            if (temperature > 600) {
                status = "returning home";
                speed = 5;
            }
        }

        void showAttributes() {
            System.out.println("Status: " + status);
            System.out.println("Speed: " + speed);
            System.out.println("Temperature: " + temperature);
        }
    }

Solution

  • You need a main class that calls your VolcanoRobot like this:

    public class MyMain
    {
        public static void main(String[] args)
        {
            VolcanoRobot bot = new VolcanoRobot();
            bot.showAttributes();
            bot.checkTemperature();
            bot.showAttributes();
        }
    }