我有一个AsynTask
并试图检索json
并解析它,但我收到了这个错误:
03-21 11:38:07.033: E/AndroidRuntime(8439): FATAL EXCEPTION: main
03-21 11:38:07.033: E/AndroidRuntime(8439): java.lang.NullPointerException
03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONTokener.nextValue(JSONTokener.java:94)
03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONObject.<init>(JSONObject.java:154)
03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONObject.<init>(JSONObject.java:171)
03-21 11:38:07.033: E/AndroidRuntime(8439): at Dic.proj.pkg.notifService.parse_if_update(notifService.java:191)
03-21 11:38:07.033: E/AndroidRuntime(8439): at Dic.proj.pkg.notifService$1$1$1.onPostExecute(notifService.java:153)
03-21 11:38:07.033: E/AndroidRuntime(8439): at Dic.proj.pkg.notifService$1$1$1.onPostExecute(notifService.java:1)
03-21 11:38:07.033: E/AndroidRuntime(8439): at android.os.AsyncTask.finish(AsyncTask.java:631)
03-21 11:38:07.033: E/AndroidRuntime(8439): at android.os.AsyncTask.access$600(AsyncTask.java:177)
03-21 11:38:07.033: E/AndroidRuntime(8439): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
03-21 11:38:07.033: E/AndroidRuntime(8439): at android.os.Handler.dispatchMessage(Handler.java:99)
03-21 11:38:07.033: E/AndroidRuntime(8439): at android.os.Looper.loop(Looper.java:137)
03-21 11:38:07.033: E/AndroidRuntime(8439): at android.app.ActivityThread.main(ActivityThread.java:4921)
03-21 11:38:07.033: E/AndroidRuntime(8439): at java.lang.reflect.Method.invokeNative(Native Method)
03-21 11:38:07.033: E/AndroidRuntime(8439): at java.lang.reflect.Method.invoke(Method.java:511)
03-21 11:38:07.033: E/AndroidRuntime(8439): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
03-21 11:38:07.033: E/AndroidRuntime(8439): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
03-21 11:38:07.033: E/AndroidRuntime(8439): at dalvik.system.NativeStart.main(Native Method)
这是我的parse_if_update
功能:
public static String parse_if_update(String jsonResponse) {
String update="no";
try {
JSONObject json = new JSONObject(jsonResponse);
update = json.getString("update");
} catch (JSONException e) {
e.printStackTrace();
}
if(update == null){
update="no";
}
return update;
}
怎么了?我花了两天时间来解决这个问题。有时我遇到空值,但我不知道如何处理它们。