• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

invalid method declaration; return type required

 
kelvin cheung
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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

what's wrong here?
 
Lars Vegas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you need to define a return type, otherwise you have a constructor.
something like "public double finnMaks(String filnavn)"
 
Tobias Hess
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
kelvin cheung
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi again and thank you.
it should be like this

any idea what i can do with the MAKS?
thanks
 
kelvin cheung
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think i've found out :

 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic