首页 新闻 赞助 找找看

JSONObject.getString()报空指针错误,求帮助

0
悬赏园豆:5 [已解决问题] 解决于 2015-07-20 09:28
for (int i = 0; i < studentInfoList.length(); i++) {
                    JSONObject studentInfoLists =(JSONObject)studentInfoList.get(i);
                    String id1=studentInfoLists.getString("id");
                    Log.i("010101010101011", id1);//id1是有值的

                    id[i] = studentInfoLists.getString("id");//这个位置报空指针
                    Log.i("010101010101011", id[0]);
}//String[] id是已经在前面定义了
風过无痕的主页 風过无痕 | 初学一级 | 园豆:13
提问于:2015-06-21 19:08
< >
分享
最佳答案
1

你的String id1=studentInfoLists.getString("id");获取的id1是有值的,id[i] = studentInfoLists.getString("id");这个位置报空指针,那说明问题在id[i]嘛,可能是你定义数组的时候没有给定一个长度的原因。

收获园豆:5
xzq_no3 | 菜鸟二级 |园豆:226 | 2015-06-22 08:35
其他回答(4)
0

json我也没咋个了解过,你输出他studentInfoList看看是不是空

xyts | 园豆:211 (菜鸟二级) | 2015-06-21 23:09
0

id[]数组没有id = new String[n];

angelshelter | 园豆:9887 (大侠五级) | 2015-06-22 15:00
0

studentInfoLists中没有id这个键值对

羽商宫 | 园豆:2490 (老鸟四级) | 2015-06-22 21:32
0

id是String类型的吗?可以用studentInfoLists.get("id")试试。

heyesp | 园豆:223 (菜鸟二级) | 2015-06-23 16:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册