World's Smaile World's Smaile -4 years ago 236
Java Question

Error :: Main method not found in class

when I start to Running My code
i found this message in the Console Box>>>>
Error: Main method not found in class "Class name", please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application

public static void main(String[] args){
public void printPhoto(int width,int height, boolean inColor){
System.out.println("Width = " + width + " cm" );
System.out.println("Height = " + height + " cm");
if(inColor){
System.out.println("Print is Full color.");
} else {
System.out.println("Print is black and white.");
}
printPhoto(10,20,false);
}


}

Answer Source

To start a java program you need the main method which not define in your code you can make it like this :

public class Test {

    public void printPhoto(int width, int height, boolean inColor) {
        System.out.println("Width = " + width + " cm");
        System.out.println("Height = " + height + " cm");
        if (inColor) {
            System.out.println("Print is Full color.");
        } else {
            System.out.println("Print is black and white.");
        }
        // printPhoto(10, 20, false); // Avoid a Stack Overflow due the recursive call
    }

    //main class
    public static void main(String[] args) {
        Test tst = new Test();//create a new instance of your class
        tst.printPhoto(0, 0, true);//call your method with some values        
    }

}

I strongly suggest to read this documentation here Getting started with Java Language

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download