2013-03-15 156 views
0

我試圖從我的android應用程序發送電子郵件從background.Mail發送成功的附件,但仍然之後,我在日誌中得到錯誤。這裏是日誌請指導我在哪裏是錯誤和如何解決它。從Android應用程序發送電子郵件

03-14 13:37:37.697: E/MailApp(1296): Could not send email 
03-14 13:37:37.697: E/MailApp(1296): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 
03-14 13:37:37.697: E/MailApp(1296): at android.os.Handler.<init>(Handler.java:197) 
03-14 13:37:37.697: E/MailApp(1296): at android.os.Handler.<init>(Handler.java:111) 
03-14 13:37:37.697: E/MailApp(1296): at android.widget.Toast$TN.<init>(Toast.java:324) 
03-14 13:37:37.697: E/MailApp(1296): at android.widget.Toast.<init>(Toast.java:91) 
03-14 13:37:37.697: E/MailApp(1296): at android.widget.Toast.makeText(Toast.java:238) 
03-14 13:37:37.697: E/MailApp(1296): at com.example.mytest.ReadContactsActivity.SendMail(ReadContactsActivity.java:173) 
03-14 13:37:37.697: E/MailApp(1296): at com.example.mytest.ReadContactsActivity.access$0(ReadContactsActivity.java:156) 
03-14 13:37:37.697: E/MailApp(1296): at com.example.mytest.ReadContactsActivity$CountDownTask.doInBackground(ReadContactsActivity.java:131) 
03-14 13:37:37.697: E/MailApp(1296): at com.example.mytest.ReadContactsActivity$CountDownTask.doInBackground(ReadContactsActivity.java:1) 
03-14 13:37:37.697: E/MailApp(1296): at android.os.AsyncTask$2.call(AsyncTask.java:287) 
03-14 13:37:37.697: E/MailApp(1296): at java.util.concurrent.FutureTask.run(FutureTask.java:234) 
03-14 13:37:37.697: E/MailApp(1296): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
03-14 13:37:37.697: E/MailApp(1296): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 
03-14 13:37:37.697: E/MailApp(1296): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 
+3

我認爲你必須使用的AsyncTask ...發佈你的代碼.. – 2013-03-15 05:08:19

+1

能否請您發佈您的代碼?如果我沒有錯,你會在線程中傳遞一條消息。 – 2013-03-15 05:23:22

回答

1

我想你想裏面顯示Toast消息該AsynTaskdoInBackground()方法, 只是做在onPostExecute()方法....

0

你可能會使用它直接試圖在你的主線程改變一些後臺線程,如果是這樣的問題,那麼使用

runOnUiThread(new Runnable() { 
    public void run() { 
    //do your work here 
    } 
}); 
相關問題