为什么ArrayIndexOutOfBoundsException异常发生,以及如何避免它的Android? [英] Why does ArrayIndexOutOfBoundsException occur and how to avoid it in Android?
本文介绍了为什么ArrayIndexOutOfBoundsException异常发生,以及如何避免它的Android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么 ArrayIndexOutOfBoundsException异常
发生,以及如何避免它在Android的?
Why does ArrayIndexOutOfBoundsException
occur and how to avoid it in Android?
推荐答案
当您试图访问一个不存在的数组项,抛出此异常:
This exception is thrown when you try to access an array item that doesn't exist:
String [] myArray = new String[2];
myArray[2] = "something"; // Throws exception
myArray[-1] = "something"; // Throws exception
您应该检查你的指数是不是消极的,不高于该数组长度访问数组项目之前。
You should check that your index is not negative and not higher than the array length before accessing an array item.
这篇关于为什么ArrayIndexOutOfBoundsException异常发生,以及如何避免它的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文