Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When I run my code, I receive this error message:

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

My code:

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);
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
370 views
Welcome To Ask or Share your Answers For Others

1 Answer

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        
    }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...