我在寫我的第一asyctask類,但在例外結束安卓:Asyctask異常問題
我asyctask類(內部類)
private class LogoutUser extends AsyncTask<Double, Void, Void>{
@Override
protected Void doInBackground(Double... params) {
validateuser logoutuser = new validateuser();
logoutuser.logOut();
return null;
}
叫
logout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ProgressDialog dialog = new ProgressDialog(homepage.this);
dialog.setMessage("Loading...");
dialog.show();
//validateuser logoutuser = new validateuser();
//logoutuser.logOut();
new LogoutUser().execute(10.00, 10.00);
Intent loginscreen = new Intent(homepage.this, Login2.class);
loginscreen.setFlags(0x04000000);
startActivity(loginscreen);
dialog.cancel();
}
});
的地方我得到的例外
08-16 16:22:54.167: ERROR/AndroidRuntime(714): FATAL EXCEPTION: AsyncTask #1
08-16 16:22:54.167: ERROR/AndroidRuntime(714): java.lang.RuntimeException: An error occured while executing doInBackground()
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at android.os.AsyncTask$3.done(AsyncTask.java:200)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at java.lang.Thread.run(Thread.java:1019)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at android.os.Handler.<init>(Handler.java:121)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at android.app.Activity.<init>(Activity.java:680)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at a.b.Login2.<init>(Login2.java:40)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at a.b.validateuser.logOut(validateuser.java:127)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at a.b.homepage$LogoutUser.doInBackground(homepage.java:450)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at a.b.homepage$LogoutUser.doInBackground(homepage.java:1)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at android.os.AsyncTask$2.call(AsyncTask.java:185)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
08-16 16:22:54.167: ERROR/AndroidRuntime(714): ... 4 more
官方文檔不符合我的要求,我開始寫我的,並以異常結束。請看看你能否幫忙。
在此先感謝。
註銷用戶任務不涉及任何UI的東西只調用Web服務註銷。它響鈴嗎? –
validateuser.logOut(validateuser.java:127) 引用此行validateuser的第127行 –
yep dat幫助:) –