\"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
ArrayList<ArrayList<Integer>> 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
.
Here, the main problem is Array indexing and real logic indexing difference...
Start with facts that ArrayList not start with index 0
* but in your logic when you use X.add("Y") with i = 0 then logic can not find place 0 or can not recover position element 0; *
that means ... it show indexing error of outbound;
solution ;
first solution : use i< istead of i<= second solution : use i = 1 for initialization instead of i = 0;
Do not use list.set(index, element)
on a nonexistent element, since it replaces the old (nonexistent) element with a new one and returns the old one. Instead, use list.add(index, element)
and it will work.
I thingk u have mistake here
list.get(0).set(placeHolder.get(k), (int) (Math.random() * (99999) + 1));
The java.util.ArrayList.get(int index) method returns the element at the specified position in this list.
You are setting just to first element in the list arrray