2014-04-06 49 views
0

我有問題了解我的Logcat中的錯誤,請問我可以幫我解決這個問題。我的Logcat中的這個錯誤是什麼意思

04-06 08:17:54.738: E/AndroidRuntime(4491): FATAL EXCEPTION: AsyncTask #1 
    04-06 08:17:54.738: E/AndroidRuntime(4491): java.lang.RuntimeException: An error occured while executing doInBackground() 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at android.os.AsyncTask$3.done(AsyncTask.java:299) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at java.util.concurrent.FutureTask.setException(FutureTask.java:219) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at java.util.concurrent.FutureTask.run(FutureTask.java:239) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at java.lang.Thread.run(Thread.java:841) 
04-06 08:17:54.738: E/AndroidRuntime(4491): Caused by: java.lang.NullPointerException: println needs a message 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at android.util.Log.println_native(Native Method) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at android.util.Log.e(Log.java:231) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at com.example.logintest.adduser$AssCrounTask.doInBackground(adduser.java:118) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at com.example.logintest.adduser$AssCrounTask.doInBackground(adduser.java:1) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at android.os.AsyncTask$2.call(AsyncTask.java:287) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  ... 4 more 

回答

1

要報告崩潰logcat你應該使用Log.d/v/etc(TAG, Message, Throwable)而不是e.printStackTrace()


無論如何,你的代碼crashs因爲e.getMessage()可能是無效和登錄不接受null的消息。

所以你的行更改爲

Log.e("MY_APP_error!", "Error!", e); 
+0

printStacktrace()是什麼?我認爲它會報告錯誤 – mathiascolebar

+0

是的,但在控制檯應用程序中,它可以在Android中確定它不是。這將是太長的評論,所以我找到了你的答案:http://stackoverflow.com/questions/7469316/why-is-exception-printstacktrace-considered-bad-practice –

1

您放入Log的消息爲空。這是寫在這裏:

Caused by: java.lang.NullPointerException: println needs a message 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at android.util.Log.println_native(Native Method) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at android.util.Log.e(Log.java:231) 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at com.example.logintest.adduser$AssCrounTask.doInBackground(adduser.java:118) 

檢查你在使用Log消息。

+1

更多的幫助: 「MY_APP_error」 線adduser.java –

+0

118這就是我把線118 adduser.java Log.e(,e.getMessage() );這是在我的catch(IOException e) – mathiascolebar

+1

使用e.printStacktrace();而不是記錄e.getMessage() –

1

隨着你的logcat說

04-06 08:17:54.738: E/AndroidRuntime(4491): Caused by: java.lang.NullPointerException: println needs a message 
04-06 08:17:54.738: E/AndroidRuntime(4491):  at android.util.Log.println_native(Native Method) 

你有一個NullPointerException異常,可能是你叫Log.e()和可變傳遞null值。