I published my first app on Android Market today and in the developer console I got an error report sent by some user. It is in Java and this is what it says:
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1096)
Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRoot.checkThread(ViewRoot.java:2811)
at android.view.ViewRoot.requestLayout(ViewRoot.java:594)
at android.view.View.requestLayout(View.java:8180)
at android.view.View.requestLayout(View.java:8180)
at android.view.View.requestLayout(View.java:8180)
at android.view.View.requestLayout(View.java:8180)
at android.view.View.requestLayout(View.java:8180)
at android.widget.RelativeLayout.requestLayout(RelativeLayout.java:257)
at android.view.View.requestLayout(View.java:8180)
at android.view.View.setFlags(View.java:4554)
at android.view.View.setVisibility(View.java:3083)
at c.a(Unknown Source)
at c.doInBackground(Unknown Source)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
No. Some code executing in a thread other than the main thread accessed a GUI object. This is not allowed. Only the main thread that built the Activity and its views can can access anything to do with the GUI.
I finally saw the error myself today on phone. I was on a low speed GPRS network. The activity had an Adview from Admob SDK. I had set Admob to refresh after 20 seconds at Admob website itself as the new SDK wouldn't permit that to be set in code. I loaded the activity. Everything including the ad loaded fine. Then I kept the phone idle and in about 20 seconds I got the force close error and in the error report I could see the same ViewRoot$CalledFromWrongThreadException.
I believe something happened when Admob tried to refresh the ad. Could you please check the Admob library and see if something like that is possible?
Thank you so much. I am very much relieved. I was worried that this was being caused by my own code. Now I guess we just need to wait for the updated JAR file from Admob and recompile the app.
Looks like AdMob 4.0.4 final was released today. It is supposed to bring Google Adsense ads too with AdMob. I downloaded the update and recompiled one of my B4A apps with the new JAR file. It works fine for now, although I am not sure if it will crash when an Adsense ad kicks in. Google says Adsense ads will be displayed if AdMob doesn't have a relevant ad to show. So far I got AdMob ads all the time.