Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-11-2012, 12:47 AM   PM User | #1
thorax232
New Coder

 
Join Date: Jun 2010
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
thorax232 has a little shameless behaviour in the past
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..
thorax232 is offline   Reply With Quote
Old 09-11-2012, 03:17 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
thorax232 (09-11-2012)
Old 09-11-2012, 03:43 AM   PM User | #3
thorax232
New Coder

 
Join Date: Jun 2010
Posts: 20
Thanks: 1
Thanked 0 Times in 0 Posts
thorax232 has a little shameless behaviour in the past
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.
thorax232 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:33 PM.


Advertisement
Log in to turn off these ads.