ViewRoot$CalledFromWrongThreadException java error

Inman

Well-Known Member
Licensed User
Longtime User
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:

Exception class: android.view.ViewRoot$CalledFromWrongThreadException
Source method: ViewRoot.checkThread()

B4X:
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)

Any idea what this means in B4A terms?
 

Inman

Well-Known Member
Licensed User
Longtime User
You mean the person touched GUI object of one activity while the main activity was still being executed?

I tested the program extensively before uploading to market. Never encountered any such error till now.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
I don't have a Sub by the name doInBackground in my project. There are some DoEvents though. Wonder if that could be the cause.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
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?
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
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.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
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.

Anyway, please take a look.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…