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

Categories

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

java - Static Error: This class does not have a static void main method accepting String[]

I'm learning, I'm newbie but I wanted to know what I do to get "run" it. this happening a error:

Static Error: This class does not have a static void main method accepting String[].

This is the code:

/**
 * @author "LionH"
 */
public class Caneirinho {

    public static void contar() {
        int i = 1;
        String a = " Carneirinho",
            b = " pulando a cerca.",
            c = "s";

        for (i = 1; i <= 100; i++) {
            if (i == 1) {
                System.out.println(i + a + b);
            } else {     
                System.out.println(i + a + c + b);
            }
        }
    }
} // Carneirinho
See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Any Java class that you run directly must have a main method, which is the entry point, i.e., where the program starts when you execute the code.

public static void main(String args[])

Just rename your method contar() to main(String args[]) and it should work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...