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