I'm attempting to iterate through the EditText "name" and check the letters so see if they match any of the letters in the objects of the array uNamesList. If they do I want to break out of the loop and return the placement of the object that had the matching letter. At the moment I am getting this error, anyone know what might be wrong?
java.lang.StringIndexOutOfBoundsException: length=9; index=9
uNamesList.add("bob");
uNamesList.add("mike");
uNamesList.add("sike");
uNamesList.add("othername");
uNamesList.add("name");
public int getName(EditText name) {
int match = 10;
for (int i = 0; i < name.toString().length(); i++) {
for (int o = 0; o < uNamesList.size(); o++) {
char cLetter = name.toString().charAt(i);
String uName = (String)uNamesList.get(o);
char uLetter = uName.charAt(i);
if (cLetter == uLetter) {
match = o;
break;
}
}
if(match!= 10){
break;
}
}
return match;
}
Aucun commentaire:
Enregistrer un commentaire