如何解决java.lang.IndexOutOfBoundsException [英] how to fix java.lang.IndexOutOfBoundsException

查看:4290
本文介绍了如何解决java.lang.IndexOutOfBoundsException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

异常线程mainjava.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)));

请帮忙

推荐答案

您想从一个空数组得到一个元素。这就是为什么尺寸: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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆