如何修复 java.lang.IndexOutOfBoundsException [英] how to fix java.lang.IndexOutOfBoundsException
本文介绍了如何修复 java.lang.IndexOutOfBoundsException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
线程main"中的异常java.lang.IndexOutOfBoundsException:索引:0,大小:0 在 java.util.ArrayList.rangeCheck(ArrayList.java:604)
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(ArrayList.java:604)
在arraylist.java 中
in line of arraylist.java
private void rangeCheck(int index) {
if (index >= size)
throw new IndexOutOfBoundsException(outOfBoundsMsg(index));
}
在线
List lstpp = getResult(pp) ;
System.out.println("=====Persegi Panjang====");
System.out.println("luas = "+((Integer)lstpp.get(0)));
请帮忙
推荐答案
您想从空数组中获取元素.这就是为什么 Size: 0
来自异常
You want to get an element from an empty array. That's why the Size: 0
from the exception
java.lang.IndexOutOfBoundsException:索引:0,大小:0
所以你不能做 lstpp.get(0)
直到你填满数组.
So you cant do lstpp.get(0)
until you fill the array.
这篇关于如何修复 java.lang.IndexOutOfBoundsException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文