• Register
0 votes
649 views

Problem :

I am trying to learn Java, I am very newbie however I wanted to know what I do to get the "run" it. I am facing below error:

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

Below is my code:

public class MyCaneirinho {
    public static void mycontar() {
        int j= 1;
        String x = " Carneirinho",
            y = " pulando a cerca.",
           z = "s";
        for (j = 1; j <= 100;j++) {
            if (j == 1) {
                System.out.println(j + x + y);
            } else {     
                System.out.println(j + x + y + z);
            }
        }
    }
} // MyCarneirinho

 

6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

Any Java class that you want to run directly must have the main method, it is the entry point, i.e., the program starts with main() when you execute the code.

public static void main(String args[])

So your correct code should be as below :

public class MyCaneirinho {
   public static void mycontar() {
        int j= 1;
        String x = " Carneirinho",
            y = " pulando a cerca.",
           z = "s";
        for (j = 1; j <= 100;j++) {
            if (j == 1) {
                System.out.println(j + x + y);
            } else {     
                System.out.println(j + x + y + z);
            }
        }
   }
public static void main(String[] args){
   mycontar(); // call mycontar() from the main method
}
} // MyCarneirinho
9 7 4
38,600 points

Related questions

0 votes
2 answers 626 views
626 views
Problem : I am unable to figure out what is wrong with my code. When I try to compile my code I get the below message: &ldquo;Program does not contain a static 'main' method suitable for an entry point&rdquo;
asked Jan 29, 2020 jwilliam 3.9k points
1 vote
1 answer 31 views
31 views
Problem: I am totally new in programming language. So I tried to write a program using: public static void main(String args[]) But it seems to give error : public static void main(String args[]) ^ IndentationError: unexpected indent What should I do?
asked Apr 2, 2020 LizzyM 6.1k points
0 votes
1 answer 124 views
124 views
Problem : I am having following warning message. The serializable class does not declare a static final serialversionuid field of type long I would like to understand and resolve the issue. Can somebody explain me this issue with simple words? I know what OOPs is Please ... void main(String[] args) { SwingUtilities.invokeLater(new Runnable(){ public void run(){ createAndViewJFrame(); } }); } }
asked Nov 24, 2019 alecxe 7.5k points
1 vote
1 answer 21 views
21 views
Problem: I admit it that Java programming is fun but it seems confusing sometimes. I am trying to adopt somethings about method and object in java. I know how to create a method and calling it inside the main method. I have a very simple question, can a void ... have a return statement? What happens if I try to return values from a void method? A well-explanation is expected. Thanks again, guys.
asked Mar 30, 2020 Gavin 15.3k points
0 votes
1 answer 58 views
58 views
Problem : In Java, I want to have something as below : class MyClazz<T> {  static void doIt(T object) {    // More code  } } But I face below error &ldquo;Cannot make a static reference to the non-static type T&rdquo; I am unable to understand ... about a subject. Could someone clarify if such the use is possible, by the similar manner? Also, why was my original attempt went unsuccessful?
asked Jan 21, 2020 jwilliam 3.9k points
0 votes
1 answer 34 views
34 views
I was working on that but I got into some problems.
asked Nov 6, 2020 TeamScript 13.5k points
0 votes
2 answers 216 views
216 views
Problem : I am beginner in Android Studio and I have written code, but I keep facing below error if I try to run my code: "Error: method does not override or implement a method from a supertype". I have already spent over four hours on this error but I am unable to fix it. Can somebody help me in fixing this issue?
asked Feb 26, 2020 mphil 2.3k points
0 votes
1 answer 8 views
8 views
What does this mean, what causes it, and how should you fix it?
asked Jan 22 TeamScript 13.5k points
0 votes
1 answer 8 views
8 views
What does this mean, what causes it, and how should you fix it?
asked Dec 15, 2020 TeamScript 13.5k points
3 votes
2 answers 843 views
843 views
Problem: I am assuming a bunch of helpful souls are roaming here, in Kodlogs. I am trying to figuring out the abstract method in Java and wrote a simple program on it. Unfortunately, my program throws back an error and says, AbstractClassExample.java:9: error: AbstractClassExample ... (String args[]) { new AbstractClassExample().display(); } } Do you have any idea or solution for me? Thanks, guys.
asked Mar 25, 2020 Gavin 15.3k points