• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

invalid method declaration; return type required

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


ERROR

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


what's wrong here?
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you need to define a return type, otherwise you have a constructor.
something like "public double finnMaks(String filnavn)"
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hm... but i get " missing return value "
on my CATCH exception,
when i write
"public double finnMaks(String filnavn)" ?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think i've found out :

 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
He baked a muffin that stole my car! And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic