* @param customerName A customer on one of the loans.
* @return The Loan corresponding to the customer. If there is no
* loan for this customer, return null.
*/
public Loan find(String customerName) //***************method getting errors************///
//***************method getting errors************///
{
String compare;
String name = customerName;
//int namelength = name.length();
for (int i = 0; i < loanArray.length; i++)
{
compare = loanArray[i].getCustomerName();
//compare = loanArray[i].substring(0, (namelength)); statement wouldn't work
if (name.equalsIgnoreCase(compare))
{
//rtval = true;
return loanArray[i];
}
else
return null;
}
} ///////////************* I'm getting missing return statement
/////////////////////////////////// error ---here,,,,,WHY???
Java Array - error saying missing return Statementmethod missing return statement error
Page 1 of 1
2 Replies - 7266 Views - Last Post: 25 March 2006 - 02:09 PM
Replies To: Java Array - error saying missing return Statement
#2
Re: Java Array - error saying missing return Statement
Posted 25 March 2006 - 01:29 PM
Because the for cycle might not execute at all (if the condition is false right at start), and after the for there is no return statement.
Also, I think you have a fault in your program's logic, as your for cycle will only examine the first object of the array (due to the else branch of the if statement).
Also, I think you have a fault in your program's logic, as your for cycle will only examine the first object of the array (due to the else branch of the if statement).
#3
Re: Java Array - error saying missing return Statement
Posted 25 March 2006 - 02:09 PM
public Loan find(String customerName)
Per your method statement, you need to return a Loan object.
return loanArray[i];
Here you are returning an array, not a Loan object.
This post has been edited by jayman9: 25 March 2006 - 02:11 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|