Reputation: 89
Whenever i try and run my code i get an error array out of bounds.
trans = new ArrayList<List<Transition>>(5);
ArrayList<Transition> t = new ArrayList<Transition>(5);
for (j = 0; j <5; j++)
trans.get(j).addAll(t); // <- Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
Upvotes: 0
Views: 77
Reputation: 37023
You have an empty list of size 0 when you create your list of lists and then you say get(i) which will try to compare size with i and jdk expect size to be greater than the index i.
So probably you could do something like:
trans = new ArrayList<List<Transition>>(5);
for (j = 0; j <5; j++) {
trans.add(new ArrayList<Transition>());
}
ArrayList<Transition> t = new ArrayList<Transition>(5);
for (j = 0; j <5; j++)
trans.get(j).addAll(t); // <- out of bounds
Upvotes: 4
Reputation: 1583
Your trans
list is empty. You didn't add
anything to it. When you run trans.get(j)
it can't get anything.
Upvotes: 1