java - 解析 JSON 数据时出现 ArrayIndexOutOfBoundsException 错误

标签 java android arrays json indexoutofboundsexception

我在 id[i] = c.getString(TAG_ID); 收到 ArrayIndexOutOfBoundsException|

代码如下:

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

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

最佳答案

id 应该是至少包含 25 个元素的数组,以避免索引越界。

String [] id = new String[25];

关于java - 解析 JSON 数据时出现 ArrayIndexOutOfBoundsException 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29148995/

相关文章:

java - Android SeekBar 更新音量按钮点击

java - 构建期间重复输入

android - 从 RemoteViews 获取 TextView 使其文本可滚动

javascript - 为什么在reduce过程中插入原始数组的项目没有调用Array.reduce函数?

javascript - 如何将字符串中的数组转换为Javascript上的数组?

java - 为什么我无法从 sun.misc.DelegatingClassLoader 查找类

java - 2个位置之间的距离法

java - int 对象到整数转换的问题

javascript - 未捕获的范围错误: Callstack exceeded when trying to convert Int8Array to String/JSON

java - Calendar.getTime IllegalArgumentException