I would like to know what to think when I type out what should be a perfectly good method, but it doesn’t get recognized as a method. Here it is.
private GObject getCollidingObject() {
gobj = getElementAt(ball.getX(),ball.getY());
if (gobj != null) {
return gobj;
}
gobj = getElementAt(ball.getX()+BALL_RADIUS,ball.getY());
if (gobj != null) {
return gobj;
}
gobj = getElementAt(ball.getX(),ball.getY()+BALL_RADIUS);
if (gobj != null) {
return gobj;
}
gobj = getElementAt(ball.getX()+BALL_RADIUS,ball.getY()+BALL_RADIUS);
if (gobj != null) {
return gobj;
}
}
Now eclipse is telling me that “This method must return a result of type GObject,” and is NOT highlighting the GObject in purple, which is its usual way of telling me that it is happy with my work.
What should I be thinking? I looked carefully over all my open-closed brackets and all my other methods are working, so I don’t think I have it placed this method within the wrong scope…
At the bottom of my program with all my other instance variables, I had
private GObject gobj;
But that doesn’t seem to be helping me out.
Thanks for any pointers.
The compiler is complaining that your
gobjis not declared as aGObject. It doesn’t matter what it actually is a an instance of, it needs to either be declared to be the return type (or one of its sublcasses/implemented classes or interfaces) or be successfully cast as such.What is
gobjdeclared as?EDIT:
And of course, you need to ensure that there is a return statement for in EVERY case.
You do not have a default that would be hit if all of your
ifstatements evaluate tofalse.