0

我正在尝试从后台从我的 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)
4

2 回答 2

1

我认为您正在尝试在方法中显示Toast消息AsynTask doInBackground(),只需在onPostExecute()方法中执行即可....

于 2013-03-15T05:26:35.910 回答
0

您可能正在使用一些直接尝试在主线程中进行更改的后台线程,如果这是问题,请使用

runOnUiThread(new Runnable() {
  public void run() {
    //do your work here
  }
});
于 2013-03-15T05:21:52.323 回答