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

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -