I get some data as a JSON response from the server. I am retrieving the data I need and I want to put this data in a string array. I do not know the size of the data, so I can not declare the array as static. I declare a dynamic array of strings:
String[] xCoords = {};
After that, I insert the data into the array:
for (int i=0; i<jArray.length(); i++) { JSONObject json_data = jArray.getJSONObject(i); xCoords[i] = json_data.getString("xCoord"); }
But I get
java.lang.ArrayIndexOutOfBoundsException Caused by: java.lang.ArrayIndexOutOfBoundsException
What is the way to dynamically insert strings into a string array?
android arrays dynamic
Stefan doychev
source share