gpt4 book ai didi

android - 将项目放在字符串数组中?

转载 作者:行者123 更新时间:2023-11-29 14:55:58 25 4
gpt4 key购买 nike

我有一个小问题。我想将一些字符串放在 String[] 中。我该怎么做?

我试过了

String[] categorys;
for (int i = 0; i < jArray.length(); i++) {
JSONObject jsdata = jArray.getJSONObject(i);
String myString = jsdata.getString("id_category");
String namecategory = jsdata.getString("category_name");
System.out.println("Category name" + namecategory);
categorys[i] = namecategory;
}

但我得到 07-28 16:40:01.719: ERROR/AndroidRuntime(452): Caused by: java.lang.ArrayIndexOutOfBoundsException

我不知道如何使用字符串数组。需要一些帮助。谢谢...

最佳答案

您需要分配数组。

String[] categorys = new String[jArray.length()];

关于android - 将项目放在字符串数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6860034/

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