解析JSON数据时出现ArrayIndexOutOfBoundsException错误

Har*_*are 3 java arrays android json indexoutofboundsexception

我在获取ArrayIndexOutOfBoundsException id[i] = c.getString(TAG_ID);

这是代码:

for (int i = 0; i < 25; i++) {
    JSONObject c = contacts.getJSONObject(i);
    id[i] = c.getString(TAG_ID);
}
Run Code Online (Sandbox Code Playgroud)

我检查过JSON文件包含25个对象.我也试过使用i<10但它仍然给出了同样的错误.

tim*_*rau 5

id 应该是一个至少包含25个元素的数组,以避免索引超出范围.

String [] id = new String[25];
Run Code Online (Sandbox Code Playgroud)