views:

315

answers:

1

Hi

I have an activity that starts with an AsyncTask to check the connection to my servers api. Since this should not run in the UI thread i have made a AsyncTask for this.

The problem is that is get an runtime exception when i start the background process of the Asynctask.

How can i avoid this?

From log:

10-12 14:18:56.476: ERROR/AndroidRuntime(1523): java.lang.RuntimeException: An error occured while executing doInBackground()
10-12 14:18:56.476: ERROR/AndroidRuntime(1523):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
10-12 14:18:56.476: ERROR/AndroidRuntime(1523):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:234)
10-12 14:18:56.476: ERROR/AndroidRuntime(1523):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:258)
10-12 14:18:56.476: ERROR/AndroidRuntime(1523):     at java.util.concurrent.FutureTask.run(FutureTask.java:122)
10-12 14:18:56.476: ERROR/AndroidRuntime(1523):     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648)
10-12 14:18:56.476: ERROR/AndroidRuntime(1523):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673)
10-12 14:18:56.476: ERROR/AndroidRuntime(1523):     at java.lang.Thread.run(Thread.java:1058)
10-12 14:18:56.476: ERROR/AndroidRuntime(1523): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
10-12 14:18:56.476: ERROR/AndroidRuntime(1523):     at android.os.Handler.<init>(Handler.java:121)
+1  A: 

Are you creating the AsyncTask in a thread other than the UI thread? This is next to impossible to debug w/o seeing the code you're using.

fiXedd