0

我有来自我的网站的 Json 响应,我解析了该响应。我可以毫无问题地写入屏幕解析数据,但是当我想分配二维数组时出现 NullPoniterException 错误。

我像这样定义了数组和jsonarray和jsonobject ...

final String[][] sonuclarDizi = null;
    String kayitSayisi = jObj.getString("kayitSayisi");
 int kayitsay = Integer.parseInt(kayitSayisi.toString());
 JSONArray menuitemArray = jObj.getJSONArray("sonuclar");


for (int i = 0; i < kayitsay; i++) {
                                System.out.println(i+". sonucun sube id si "+menuitemArray.getJSONObject(i).getString("sube_id"));
                                System.out.println(i+". sonucun ders_id si "+menuitemArray.getJSONObject(i).getString("ders_id"));
                                System.out.println(i+". sonucun kodu si "+menuitemArray.getJSONObject(i).getString("kodu"));
                                System.out.println(i+". sonucun adi si "+menuitemArray.getJSONObject(i).getString("adi"));
                                System.out.println(i+". sonucun ortalama_yazi si "+menuitemArray.getJSONObject(i).getString("ortalama_yazi"));
                                System.out.println(i+". sonucun sube id si "+menuitemArray.getJSONObject(i).getString("kredi"));
                                System.out.println(i+". sonucun devamDurumu si "+menuitemArray.getJSONObject(i).getString("devamDurumu"));
                                System.out.println(i+". sonucun sube id si "+menuitemArray.getJSONObject(i).getString("ortalama"));
                                System.out.println(i+". sonucun sonuc si "+menuitemArray.getJSONObject(i).getString("sonuc"));
                                System.out.println(i+". sonucun sube id si "+menuitemArray.getJSONObject(i).getString("basarili"));
                                System.out.println(i+". sonucun harf si "+menuitemArray.getJSONObject(i).getString("harf"));
                            } 

这部分正在工作。但下面部分返回 NullPointerException 错误。

for (int i = 0; i < kayitsay; i++) {
                                sonuclarDizi[i][1]=(menuitemArray.getJSONObject(i).getString("sube_id"));
                                sonuclarDizi[i][1]=(menuitemArray.getJSONObject(i).getString("ders_id"));
                                sonuclarDizi[i][1]=(menuitemArray.getJSONObject(i).getString("kodu"));
                                sonuclarDizi[i][1]=(menuitemArray.getJSONObject(i).getString("adi"));
                                sonuclarDizi[i][1]=(menuitemArray.getJSONObject(i).getString("ortalama_yazi"));
                                sonuclarDizi[i][1]=(menuitemArray.getJSONObject(i).getString("kredi"));
                                sonuclarDizi[i][1]=(menuitemArray.getJSONObject(i).getString("devamDurumu"));
                                sonuclarDizi[i][1]=(menuitemArray.getJSONObject(i).getString("ortalama"));
                                sonuclarDizi[i][1]=(menuitemArray.getJSONObject(i).getString("sonuc"));
                                sonuclarDizi[i][1]=(menuitemArray.getJSONObject(i).getString("basarili"));
                                sonuclarDizi[i][1]=(menuitemArray.getJSONObject(i).getString("harf"));
                            }

非常感谢...

4

1 回答 1

0

sonuclarDizi是一个空数组。您声明了它,但您需要先实例化它,然后才能向它添加项目。

String[][] sonuclarDizi;

sonuclarDizi = new String[kayitsay][];

for (int i = 0; i < kayitsay; i++) {
  sonuclarDizi[i] = new String[11];
  /* ... */
}
于 2013-03-29T14:02:40.983 回答