• 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

I have no idea what is wrong with this code

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no idea what is wrong with this. I keep trying to compile it but I keep getting this error.....
"Error: invalid method declaration; return type required"

Any help would be greatly appreciated. I'm new to java and it's so frustrating.

Thanks!!!


public Pair(double aF, double aS)
{
aFirst = aF;
aSecond = aS;
}

public double getFirst()
{
return aFirst;
}

public double getSecond()
{
return aSecond;
}
 
Ranch Hand
Posts: 50
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Renee,

It says return type required, and out of the three methods only one has no return type.



HINT:
I am unsure what your code is to do as it's not complete, but if everything else is good it could be rectified with a word in line 1.

edit. unless Pair is also your class name which it appears to be with the naming convention.

cheers,
Daniel
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Like Daniel rightly said, this looks like a constructor.
If that is the case, what is the name of your java class?
Since Java is case sensitive, it should be Pair (and not pair)

If you have defined it as pair (with a lower case p) the compiler thinks public Pair(..) is a method which is lacking a return type and complains accordingly
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic