Click here to Skip to main content
12,074,926 members (55,473 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Java
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 (
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 1-Apr-13 11:34am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

The message is simple: you can not start an application that has no entry point. See the most used demo:
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.
  Permalink  
Comments
   
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!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
helloworld..s 1-Apr-13 16:41pm
   
Thank you!
   
You are welcome.
Good luck, call again.
—SA
Zoltán Zörgő 1-Apr-13 16:41pm
   
Of course, it is also a 5!
   
Thank you, Zoltán.
—SA

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160208.1 | Last Updated 1 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100