In an app I'm writing, I'm loading an XML into a Java String[], then turning each item into an object and adding these to an array of objects.
Below is my code:
The Java part, with a do-while loop
ArrayList<ExpandListGroup> list = new ArrayList<ExpandListGroup>();
ArrayList<ExpandListChild> list2 = new ArrayList<ExpandListChild>();
ExpandListGroup gru1 = new ExpandListGroup();
gru1.setName(getString(R.string.album_vancouver));
String[] tempArray = getResources().getStringArray(R.array.album_array_vancouver);
int count = 0;
int max = tempArray.length;
do {
ExpandListChild ch = new ExpandListChild();
ch.setName(tempArray[count]);
ch.setTag(null);
list2.add(ch);
} while(count <= max);
gru1.setItems(list2);
list.add(gru1);
And the arrays in XML
<string name="album_vancouver">Vancouver</string>
<string name="song_vancouver_1">Future Wars</string>
<string name="song_vancouver_2">A Word Of Welcome And Of Warning</string>
<string name="song_vancouver_3">See You In Vancouver</string>
<string name="song_vancouver_4">To Withstand The Force Of Storms</string>
<string name="song_vancouver_5">He Is Here, He Is Not Afraid</string>
<string name="song_vancouver_6">The Surgeon And The Scientist</string>
<string name="song_vancouver_7">Fairmount</string>
<string name="song_vancouver_8">Untitled</string>
<string-array name="album_array_vancouver">
<item>@string/song_vancouver_1</item>
<item>@string/song_vancouver_2</item>
<item>@string/song_vancouver_3</item>
<item>@string/song_vancouver_4</item>
<item>@string/song_vancouver_5</item>
<item>@string/song_vancouver_6</item>
<item>@string/song_vancouver_7</item>
<item>@string/song_vancouver_8</item>
</string-array>
I get a java.lang.OutOfMemoryError at runtime, at the line "list2.add(ch)".
What can I do to make this work?