“Exception in thread ”main“ java.lang.IndexOutOfBoundsException: Index: 0, Size: 0” with ArrayList?

前端 未结 4 1284
长情又很酷
长情又很酷 2020-12-11 23:12

\"Exception in thread \"main\" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0\" is the main error I get when I compile this method:

public static Arr         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-11 23:50

    ArrayList> list doesnt contain any element in (0)th postion and the compiler throws out of bounds exception on iterating when it doesn't find any element in the specified postion.

    when you try executing list.get(0).set(placeHolder.get(k), (int) (Math.random() * (99999) + 1)); statement , your list doesnt contain any element inside it. you need to iterate the inner list to set the values for the list.

提交回复
热议问题