Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Newbie Questions and Hello!

    I'm working on two basic programs, I'm just learning java and getting some errors I don't understand.

    The first program uses the "double" for variables in order to print decimals. I know I'm not using it right but this is what I have:
    Code:
    public class Prog4 {
            public static main(String[]) {
            double calc;
    
                    //Formula
                    calc = (((9.5*4.5)-(2.5*3))/(45.5-3.5));
                    //Print results
                    System.out.println(calc);
            }
    }
    and this is the error I get:
    Code:
    Prog4.java:2: invalid method declaration; return type required
            public static main(String[]) {
                          ^
    Prog4.java:2: <identifier> expected
            public static main(String[]) {
    I know terrible. The other program I know is written correctly I have others like it, it just prints out some text. But I get this error after successfully compiling and trying to run.
    Code:
    Exception in thread "main" java.lang.NoSuchMethodError: main
    I think it's worth mentioning I'm doing this in the VI editor.
    Last edited by thorax232; 09-11-2012 at 03:44 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Editor doesn't matter. These errors are essentially caused by the same thing. The first one is complaining that there is no valid return result from the method, and the second is that it is missing the main method (since its not correctly defined). Simply add void as your return type and give your String[] a variable name, and the class will compile and run.

  • Users who have thanked Fou-Lu for this post:

    thorax232 (09-11-2012)

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    20
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Thumbs up

    Quote Originally Posted by Fou-Lu View Post
    Editor doesn't matter. These errors are essentially caused by the same thing. The first one is complaining that there is no valid return result from the method, and the second is that it is missing the main method (since its not correctly defined). Simply add void as your return type and give your String[] a variable name, and the class will compile and run.
    Derp, I was missing things like "void" and "args" in both programs. Should've caught those myself. Thanks a lot.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •