每次尝试运行此代码时都会出现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