致命异常:AsyncTask#1引起:java.lang.NullPointerException

时间:2014-02-19 14:05:25

标签: java android json android-asynctask nullpointerexception

我在mainActivity的第275行中获得了一个带有NullPointerException的FATAL EXCEPTION(Log.d(“Create Response”,json.toString());)我之前引用了该对象作为JSONObject json = new JSONObject() ;我仍然得到空指针。我的日志猫在下面。

Log cat:

02-19 08:56:34.101: E/AndroidRuntime(1913): FATAL EXCEPTION: AsyncTask #1
02-19 08:56:34.101: E/AndroidRuntime(1913): Process: com.example.newjudoapp, PID: 1913
02-19 08:56:34.101: E/AndroidRuntime(1913): java.lang.RuntimeException: An error occured while executing doInBackground()
02-19 08:56:34.101: E/AndroidRuntime(1913):     at android.os.AsyncTask$3.done(AsyncTask.java:300)
02-19 08:56:34.101: E/AndroidRuntime(1913):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
02-19 08:56:34.101: E/AndroidRuntime(1913):     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
02-19 08:56:34.101: E/AndroidRuntime(1913):     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
02-19 08:56:34.101: E/AndroidRuntime(1913):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-19 08:56:34.101: E/AndroidRuntime(1913):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-19 08:56:34.101: E/AndroidRuntime(1913):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-19 08:56:34.101: E/AndroidRuntime(1913):     at java.lang.Thread.run(Thread.java:841)
02-19 08:56:34.101: E/AndroidRuntime(1913): Caused by: java.lang.NullPointerException
02-19 08:56:34.101: E/AndroidRuntime(1913):     at com.example.newjudoapp.MainActivity$selectUser.doInBackground(MainActivity.java:275)
02-19 08:56:34.101: E/AndroidRuntime(1913):     at com.example.newjudoapp.MainActivity$selectUser.doInBackground(MainActivity.java:1)
02-19 08:56:34.101: E/AndroidRuntime(1913):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
02-19 08:56:34.101: E/AndroidRuntime(1913):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-19 08:56:34.101: E/AndroidRuntime(1913):     ... 4 more

3 个答案:

答案 0 :(得分:0)

无论你得到什么......

json = jsonParser.hybridHTTPReuest(url, "POST", "GET", params);

...是null

当您实例化一个新实例时,然后使用它并根据解析器的返回值将其值设置为null

答案 1 :(得分:0)

请检查返回“hybridHTTPReuest()”为空的内容

答案 2 :(得分:0)

你传递给json方法的Log.d("Create Response", json.toString() )为空,并且该方法需要打印字符串,检查你的jsonParser.hybridHTTPReuest(url, "POST", "GET", params);方法是否返回任何值,同时你可以使用Log.d("Create Response", json.toString() +"")