Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java IndexOutOfBoundsException:索引:0,大小:0 2D Arraylist_Java_Eclipse_Arraylist_2d_Dimension - Fatal编程技术网

Java IndexOutOfBoundsException:索引:0,大小:0 2D Arraylist

Java IndexOutOfBoundsException:索引:0,大小:0 2D Arraylist,java,eclipse,arraylist,2d,dimension,Java,Eclipse,Arraylist,2d,Dimension,我认为数组列表是动态的,我不知道为什么会收到这个错误。我花了很多时间在这个问题上,但没有解决它。非常感谢您的帮助。 提前谢谢 Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown Source)

我认为数组列表是动态的,我不知道为什么会收到这个错误。我花了很多时间在这个问题上,但没有解决它。非常感谢您的帮助。 提前谢谢

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.rangeCheck(Unknown Source)
    at java.util.ArrayList.get(Unknown Source)
    at Implementation_Method.main(Implementation_Method.java:53)
在此之前,您似乎没有向
Pareto\u set\u列表添加任何
ArrayList
实例,因此ArrayList为空。当您尝试检索位于
优化\u问题.常规\u计算.获取另一个\u解决方案
(似乎为0)的元素时,将引发异常

您可以做的是将
ArrayList
添加到
Pareto\u set\u列表中,如下所示:

Pareto_set_List.get(Optimization_Problem.General_Calculation.Get_Another_Solution).add(EncodingUtils.getInt(solution.getVariable(j)));
Pareto_set_List.add(newarraylist());

您可以找到有用的信息和几个链接。

感谢您的回复,但我已经在开始时定义了数组列表ArrayList Pareto_set_list=new ArrayList();我需要在这一点之前执行这一步吗?你是说Pareto_set_List.get(优化问题.一般计算.获取另一个解决方案).add(EncodingUtils.getInt(解决方案.getVariable(j));您可能已经定义并初始化了
Pareto\u set\u列表
,但在调用
get
之前是否向其添加了任何
ArrayList
实例?如果不这样做,ArrayList的大小将为0,尝试访问任何索引处的元素都会导致抛出异常。不,我不知道,因为这是一个二维arraylist,所以我需要调用get和add-together,我不知道其他方法。在调用get-PleaseEyes之前,你能举个例子说明如何向其中添加任何arraylist实例吗,但是在空的ArrayList上调用
get
会抛出一个异常,这正是我试图理解的要点。在调用
get
之前,只需在
Pareto\u set\u列表中添加一个
ArrayList
Pareto_set_List.get(Optimization_Problem.General_Calculation.Get_Another_Solution).add(EncodingUtils.getInt(solution.getVariable(j)));
Pareto_set_List.add(new ArrayList<Integer>());