aspose file tools*
The moose likes Beginning Java and the fly likes invalid method declaration; return type required Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "invalid method declaration; return type required" Watch "invalid method declaration; return type required" New topic
Author

invalid method declaration; return type required

kelvin cheung
Ranch Hand

Joined: Mar 27, 2004
Posts: 120


ERROR
invalid method declaration; return type required
public finnMaks(String filnavn)
^
1 error

what's wrong here?
Lars Vegas
Greenhorn

Joined: Dec 04, 2001
Posts: 27
you need to define a return type, otherwise you have a constructor.
something like "public double finnMaks(String filnavn)"
Tobias Hess
Ranch Hand

Joined: Apr 06, 2004
Posts: 55
you need to define a return type,
otherwise you have a constructor.

Otherwise you have an error; the only place where a return type must be omitted is the constructor.
kelvin cheung
Ranch Hand

Joined: Mar 27, 2004
Posts: 120
hm... but i get " missing return value "
on my CATCH exception,
when i write
"public double finnMaks(String filnavn)" ?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Because every path out of the function has to return a value. Add a "return 0" to the catch, or, perhaps better, don't catch the exception, but let it propagate to tell the caller that no value could be returned.


[Jess in Action][AskingGoodQuestions]
kelvin cheung
Ranch Hand

Joined: Mar 27, 2004
Posts: 120
thanks guys!
so far i have added "return 0;" on the catch.
and it works fine.
but i got another error when i write :

error :
GUI.java [149:1] cannot resolve symbol
symbol : variable maks
location: class GUI
String stringMaks = Double.parseDouble(maks);
^
GUI.java [149:1] incompatible types
found : double
required: java.lang.String
String stringMaks = Double.parseDouble(maks);
^
2 errors

it says that it cannot resolve symbol?
but "maks" has been returned back..
Tobias Hess
Ranch Hand

Joined: Apr 06, 2004
Posts: 55
it says that it cannot resolve symbol?
but "maks" has been returned back..

No, the value of maks has been returned, not maks itself. If you want to do something with that value, you have to store it like this:
double x = finnMaks(f);
There's another problem here:
String stringMaks = Double.parseDouble(maks);
Double.parseDouble() makes a double from a string, this is not what you want - you really want the opposite, and I'm not sure but it has to be something like this:
Double d = new Double(x);
String stringMaks = d.toString();
HTH
[ April 13, 2004: Message edited by: Tobias Hess ]
kelvin cheung
Ranch Hand

Joined: Mar 27, 2004
Posts: 120
hi again and thank you.
it should be like this

any idea what i can do with the MAKS?
thanks
kelvin cheung
Ranch Hand

Joined: Mar 27, 2004
Posts: 120
i think i've found out :

Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
You have the right idea. However, you also need to initialize the value of maks:

I might suggest that you use a different variable name. This will help you understand that this maks is different than the maks that is declared in finnMaks.
Layne


Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: invalid method declaration; return type required