• Post Reply Bookmark Topic Watch Topic
  • New Topic

I have no idea what is wrong with this code  RSS feed

 
Renee Crozier
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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;
}
 
Daniel Hirning
Ranch Hand
Posts: 50
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!