This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Why is the error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why is the error "missing return statement"" Watch "Why is the error "missing return statement"" New topic

Why is the error "missing return statement"

Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167

The TestDrive has the "main"
When the return statement is included why do I get the error "Missing return statement".Is there a particular place where the return statement should be situated.


Varuna Seneviratna
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42956
The checkUserGuess does not in all cases return something. If the locationCells array is empty, no return statement is ever reached.
ruban raj

Joined: Aug 05, 2008
Posts: 7
You have to place return statement out of "for loop" in side of checkUserGuess() method.

Thanks and regards,

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 43282
Originally posted by ruban raj:
You have to place return statement out of "for loop" . . .

Agree. In fact the return statements, if they are actually executed, will break the repetition by terminating the loop.
subject: Why is the error "missing return statement"
It's not a secret anymore!