java - Why does ArrayIndexOutOfBoundsException occur and how to avoid it in Android? -


why arrayindexoutofboundsexception occur , how avoid in android?

this exception thrown when try access array item doesn't exist:

string [] myarray = new string[2];  myarray[2] = "something"; // throws exception myarray[-1] = "something"; // throws exception 

you should check index not negative , not higher array length before accessing array item.


Comments