gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:06:22 26 4
gpt4 key购买 nike

我在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com