Click here to Skip to main content
Rate this: bad
good
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
Sergey Alexandrovich Kryukov at 1-Apr-13 16:40pm
   
My 5. We answered almost at the same time. :-)
—SA
Zoltán Zörgő at 1-Apr-13 16:41pm
   
Yes :)
helloworld..s at 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 at 1-Apr-13 16:41pm
   
Thank you!
Sergey Alexandrovich Kryukov at 1-Apr-13 16:42pm
   
You are welcome.
Good luck, call again.
—SA
Zoltán Zörgő at 1-Apr-13 16:41pm
   
Of course, it is also a 5!
Sergey Alexandrovich Kryukov at 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)

  Print Answers RSS
0 BillWoodruff 330
1 Mathew Soji 309
2 Maciej Los 295
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 217
0 OriginalGriff 6,369
1 Sergey Alexandrovich Kryukov 5,973
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,025


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 1 Apr 2013
Copyright © CodeProject, 1999-2014
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