从Web服务检索json数组时的android-nullpointer异常

时间:2016-05-07 12:54:50

标签: android json rest

每次尝试运行此代码时都会出现nullpointer异常,但我没有看到任何错误。所以这里是代码:

@Override
    protected Void doInBackground(Void... params) {
        // Create an array
        arraylist = new ArrayList<HashMap<String, String>>();
        // Retrieve JSON Objects from the given URL address
        jsonobject = JSONfunctions.getJSONfromURL("http://www.focusyazilim.net/json/main.json");

        try {
            // Locate the array name in JSON
            jsonarray = jsonobject.getJSONArray("worldpopulation");

            for (int i = 0; i < jsonarray.length(); i++) {
                HashMap<String, String> map = new HashMap<String, String>();
                jsonobject = jsonarray.getJSONObject(i);
                // Retrive JSON Objects
                map.put("şehir", jsonobject.getString("rank"));
                map.put("ülke", jsonobject.getString("country"));
                map.put("nüfus", jsonobject.getString("population"));
                // Set the JSON Objects into the array
                arraylist.add(map);
            }
        } catch (JSONException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return null;

    }

可能导致nullpointer异常的问题是什么?这是错误:enter image description here

0 个答案:

没有答案