我编写了一个从 Internet 读取数据的 AsyncTask 扩展类。尽管代码在模拟器(GB)中运行良好,即;它正在从互联网返回数据,但是当我在手机 (JB) 上运行代码时,它不会返回任何内容。此外,代码在 emualtor 的 logcat 中创建了以下异常。这是代码:
new userCred().execute(userCredentials);
public class userCred extends AsyncTask<String[], String, String>
{
@Override
protected String doInBackground(String[]... arg0) {
......
startActivity(intent);
return null; // because I am not returning anythign
}
}
日志猫:
07-15 21:49:56.768: W/System.err(1542): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
07-15 21:49:56.768: W/System.err(1542): at android.os.Handler.<init>(Handler.java:121)
07-15 21:49:56.768: W/System.err(1542): at android.widget.Toast.<init>(Toast.java:68)
07-15 21:49:56.768: W/System.err(1542): at android.widget.Toast.makeText(Toast.java:231)
07-15 21:49:56.768: W/System.err(1542): at com.umer.androiduetproject.LoginAccount.sendCredentialsForCheckingOnline(LoginAccount.java:71)
07-15 21:49:56.768: W/System.err(1542): at com.umer.androiduetproject.LoginAccount$userCred.doInBackground(LoginAccount.java:124)
07-15 21:49:56.768: W/System.err(1542): at com.umer.androiduetproject.LoginAccount$userCred.doInBackground(LoginAccount.java:1)
07-15 21:49:56.768: W/System.err(1542): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-15 21:49:56.768: W/System.err(1542): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
07-15 21:49:56.768: W/System.err(1542): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
07-15 21:49:56.768: W/System.err(1542): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
07-15 21:49:56.768: W/System.err(1542): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
07-15 21:49:56.768: W/System.err(1542): at java.lang.Thread.run(Thread.java:1019)
07-15 21:50:24.169: W/System.err(1542): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
07-15 21:50:24.169: W/System.err(1542): at android.os.Handler.<init>(Handler.java:121)
07-15 21:50:24.169: W/System.err(1542): at android.widget.Toast.<init>(Toast.java:68)
07-15 21:50:24.169: W/System.err(1542): at android.widget.Toast.makeText(Toast.java:231)
07-15 21:50:24.169: W/System.err(1542): at com.umer.androiduetproject.LoginAccount.sendCredentialsForCheckingOnline(LoginAccount.java:71)
07-15 21:50:24.169: W/System.err(1542): at com.umer.androiduetproject.LoginAccount$userCred.doInBackground(LoginAccount.java:124)
07-15 21:50:24.169: W/System.err(1542): at com.umer.androiduetproject.LoginAccount$userCred.doInBackground(LoginAccount.java:1)
07-15 21:50:24.169: W/System.err(1542): at android.os.AsyncTask$2.call(AsyncTask.java:185)
07-15 21:50:24.179: W/System.err(1542): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
07-15 21:50:24.179: W/System.err(1542): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
07-15 21:50:24.179: W/System.err(1542): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
07-15 21:50:24.179: W/System.err(1542): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
07-15 21:50:24.179: W/System.err(1542): at java.lang.Thread.run(Thread.java:1019)
JB LOGCAT:
07-15 18:51:36.378: E/ActivityThread(1466): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@b50afe10 that was originally bound here
07-15 18:51:36.378: E/ActivityThread(1466): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@b50afe10 that was originally bound here
07-15 18:51:36.378: E/ActivityThread(1466): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
07-15 18:51:36.378: E/ActivityThread(1466): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
07-15 18:51:36.378: E/ActivityThread(1466): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
07-15 18:51:36.378: E/ActivityThread(1466): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
07-15 18:51:36.378: E/ActivityThread(1466): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
07-15 18:51:36.378: E/ActivityThread(1466): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
07-15 18:51:36.378: E/ActivityThread(1466): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
07-15 18:51:36.378: E/ActivityThread(1466): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
07-15 18:51:36.378: E/ActivityThread(1466): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
07-15 18:51:36.378: E/ActivityThread(1466): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
07-15 18:51:36.378: E/ActivityThread(1466): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
07-15 18:51:36.378: E/ActivityThread(1466): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-15 18:51:36.378: E/ActivityThread(1466): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
07-15 18:51:36.378: E/ActivityThread(1466): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
07-15 18:51:36.378: E/ActivityThread(1466): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
07-15 18:51:36.378: E/ActivityThread(1466): at java.lang.Thread.run(Thread.java:856)
07-15 18:51:36.378: E/StrictMode(1466): null
07-15 18:51:36.378: E/StrictMode(1466): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@b50afe10 that was originally bound here
07-15 18:51:36.378: E/StrictMode(1466): at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
07-15 18:51:36.378: E/StrictMode(1466): at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
07-15 18:51:36.378: E/StrictMode(1466): at android.app.ContextImpl.bindService(ContextImpl.java:1418)
07-15 18:51:36.378: E/StrictMode(1466): at android.app.ContextImpl.bindService(ContextImpl.java:1407)
07-15 18:51:36.378: E/StrictMode(1466): at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
07-15 18:51:36.378: E/StrictMode(1466): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157)
07-15 18:51:36.378: E/StrictMode(1466): at com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145)
07-15 18:51:36.378: E/StrictMode(1466): at com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191)
07-15 18:51:36.378: E/StrictMode(1466): at com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)
07-15 18:51:36.378: E/StrictMode(1466): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551)
07-15 18:51:36.378: E/StrictMode(1466): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549)
07-15 18:51:36.378: E/StrictMode(1466): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-15 18:51:36.378: E/StrictMode(1466): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
07-15 18:51:36.378: E/StrictMode(1466): 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 07-15 18:51:36.378: E/StrictMode(1466): 在java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 07-15 18:51:36.378: E/StrictMode(1466): at java.lang.Thread.run(Thread.java:856)
问候