Pater SVK
Pater SVK

Reputation: 69

java.lang.IndexOutOfBoundsException: Index: 264

Error:

java.lang.IndexOutOfBoundsException: Index: 264, Size: 0
    at java.util.ArrayList.rangeCheckForAdd(Unknown Source)
    at java.util.ArrayList.add(Unknown Source)

My Code:

import java.util.ArrayList
...
private static ArrayList<String[]> Arr = new ArrayList<String[]>();
...
Arr.add(264, new String[] {"title","description","icon"});
Arr.add(268, new String[] {"title2","description2","icon2"});
Arr.add(1222, new String[] {"title3","description3","icon3"});

I need to add another string array with its own key

Upvotes: 0

Views: 761

Answers (1)

jtahlborn
jtahlborn

Reputation: 53694

You can't add a specific index unless the list is at least that big already.

This line:

Arr.add(264, new String[] {"title","description","icon"});

will only work if the list has at least 264 elements already (as the javadoc clearly states, should you decide to read it).

Upvotes: 2

Related Questions