. Advertisement .
..3..
. Advertisement .
..4..
I get the error: static error: this class does not have a static void main method accepting string[]. When I try to run the program below:
/**
* @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
The error appears the system notifies as follows:
Static Error: This class does not have a static void main method accepting String[].
I tried to solve it with another sample. I got the reference in the community forum, but it still returned an invalid result. If someone knows the solution, please give me the support. Thanks!
The cause:
After looking over your problem, I found that you had some classes in your Java program, but you didn’t create a main class to do the classes which you had specified. That’s the reason why you had got this error.
Solution:
To solve this error, you need to replace
contar()
tomain(String args[])
.Look at below:
If you do as my above suggestions, the error will not exist and your program will work well. Good lucks!!!
A
main
method must be present in any Java class you are running directly. This is the entry point. It tells you where the program begins when you execute the code.It should work by changing the
contar()
name tomain(String args[])