Click here to Skip to main content
16,001,823 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I created this very simple code to start learning how to program. When I went onto my terminal I first went into the correct directry, and then typed javac Calc.java. the class and java class are both present in the folder. I tried to run it after that by typing, java Calc. But I got this error (
XML
Exception in thread "main" java.lang.NoSuchMethodError: main) What could I be doing wrong here?

public class Calc {

    public void brown ()
    {
        int a = 0;
        int b = 0;
        a++;
        b--;
        System.out.println(a);
        System.out.println(b);
    }
}
Posted

The message is simple: you can not start an application that has no entry point. See the most used demo:
Java
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World");
    }
}

Do you see the difference? This will run, since it has a public static void main(String[] args) signed method. Do like this. Of course, you can have other methods too.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Apr-13 16:40pm    
My 5. We answered almost at the same time. :-)
—SA
Zoltán Zörgő 1-Apr-13 16:41pm    
Yes :)
helloworld..s 1-Apr-13 16:41pm    
thanks!
This type of application needs an entry point method, "main". As I can understand from your exception message, it is missing. Please, for example, use these directions:
http://www.cs.utexas.edu/~mitra/cwinstr.html[^].

To get some background on the topic, please see: http://en.wikipedia.org/wiki/Main_function#Java[^].

—SA
 
Share this answer
 
Comments
helloworld..s 1-Apr-13 16:41pm    
Thank you!
Sergey Alexandrovich Kryukov 1-Apr-13 16:42pm    
You are welcome.
Good luck, call again.
—SA
Zoltán Zörgő 1-Apr-13 16:41pm    
Of course, it is also a 5!
Sergey Alexandrovich Kryukov 1-Apr-13 16:43pm    
Thank you, Zoltán.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900