Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

java - Error :: Main method not found in class

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

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

1 Reply

0 votes
by (71.8m points)

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        
    }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...