<分区>
为什么会出现ArrayIndexOutOfBoundsException
,在Android中如何避免?
<分区>
为什么会出现ArrayIndexOutOfBoundsException
,在Android中如何避免?
最佳答案
当您尝试访问不存在的数组项时会抛出此异常:
String [] myArray = new String[2];
myArray[2] = "something"; // Throws exception
myArray[-1] = "something"; // Throws exception
在访问数组项之前,您应该检查您的索引是否为负数且不高于数组长度。
关于java - 为什么会出现 ArrayIndexOutOfBoundsException 以及在 Android 中如何避免?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4958235/
相关文章:
android - 在 Android 应用中使用 Google 公交信息
java - ArrayIndexOutOfBounds 异常,但没有越界?
java - char* (Array) 强制转换为 unsigned long + 1?
android - processDebugMainManifest 失败,我在使用 targetSdkVersion 为 31 时遇到此错误
java - 使用 Java 泛型确保接收到的参数与类或其子类型相同
android - Android ColorMatrix setSaturation() 是否支持大于 1 的值?