致命的な例外:私のアプリケーションではAsyncTask#2。なぜ誰かに教えてください。また、私が何をする必要があるか教えてください。私は今はかなり混乱しており、少し助けが必要です。致命的な例外asynctask#2 AndroidRuntime
は、ここに私のコード
Bundle b = getIntent().getExtras();
pDialog = new ProgressDialog(DataActivity.this);
Id = b.getString("Id");
Exists = b.getBoolean("Exists");
final String myUrl = "http://xxxxxxxxxx/api.php?id="+Id;
try
{
new MyAsyncTaskGetNews().execute(myUrl,"false");
}catch (Exception e){Log.d("d2",e.toString());}
IB = (ImageButton)findViewById(R.id.imageButton);
IB.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
try
{
new MyAsyncTaskGetNews().execute(myUrl,"true");
}catch (Exception e){Log.d("d1",e.toString());}
}
});
とlogcat
07-25 19:47:25.393 8717-9017/com.xxxxxxxx.xxxx E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2
Process: com.xxxxxxxx.xxxx, PID: 8717
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:309)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:200)
at android.os.Handler.<init>(Handler.java:114)
at android.widget.Toast$TN.<init>(Toast.java:359)
at android.widget.Toast.<init>(Toast.java:105)
at android.widget.Toast.makeText(Toast.java:266)
at com.xxxxxxxx.xxxx.DataActivity$MyAsyncTaskGetNews.doInBackground(DataActivity.java:136)
at com.xxxxxxxx.xxxx.DataActivity$MyAsyncTaskGetNews.doInBackground(DataActivity.java:93)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at
java.lang.Thread.run(Thread.java:818)
07-25 19:47:25.533 8717-8717/com.xxxxxxxx.xxxx I/Timeline: Timeline: Activity_idle id: [email protected] time:35310450
07-25 19:47:25.705 8717-8717/com.xxxxxxxx.xxxx E/WindowManager: android.view.WindowLeaked: Activity com.xxxxxxxx.xxxx.DataActivity has leaked window com.android.internal.policy.PhoneWindow$DecorView{afa2ab V.E...... R......D 0,0-1026,483} that was originally added here
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:372)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:86)
at android.app.Dialog.show(Dialog.java:326)
at com.xxxxxxxx.xxxx.DataActivity$MyAsyncTaskGetNews.onPreExecute(DataActivity.java:105)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:604)
at android.os.AsyncTask.execute(AsyncTask.java:551)
at com.xxxxxxxx.xxxx.DataActivity$1.onClick(DataActivity.java:87)
at android.view.View.performClick(View.java:5280)
at android.view.View$PerformClick.run(View.java:21239)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:5526)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
例外を助けるために、AsyncTaskクラスを参照する必要があります –