La valeur de retour d'une instruction if dans une boucle for each

J'ai cette méthode, qui utilise une boucle for each avec une instruction if dans il

public static Apartment getApartment(String aNumber)

//for loop to iterate through the list of apartments         
{   
for (Apartment x : listOfApartments) 
  { 
  //Variable to hold the value of returned apartment    
  if (x.getApartmentNo().equalsIgnoreCase(aNumber))
  { Apartment chosen = x;
  }
  else 
  {JOptionPane.showMessageDialog(null, "Apartment not found");
  }

}  
return chosen;
} 

J'obtiens une erreur que Symbole choisi de ne pas trouvé. Je pense avoir déclaré la variable dans le mauvais endroit.
Toute aide?
Note: C'est une méthode qui prend une Chaîne de caractères et renvoie un Objet de l'Appartement.

InformationsquelleAutor Sasha | 2012-04-25