0

Recently my error reporting tool started to show this crash (varies slightly depending on the manufacturer of the device due to the webviews implementation)

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
       at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:4317)
       at android.view.ViewRootImpl.invalidateChild(ViewRootImpl.java:892)
       at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:941)
       at android.view.ViewGroup.invalidateChild(ViewGroup.java:4019)
       at android.view.View.invalidate(View.java:8621)
       at android.webkit.WebView.invalidate(WebView.java:1743)
       at android.webkit.WebView.viewInvalidate(WebView.java:4065)
       at android.webkit.WebView.invalidateContentRect(WebView.java:4084)
       at android.webkit.WebView.setNewPicture(WebView.java:14353)
       at android.webkit.WebView$PrivateHandler.handleMessage(WebView.java:13747)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:137)
       at android.os.HandlerThread.run(HandlerThread.java:60)

I think this error comes from the Mopub's implementation (or from other ads sdk mediated with mopub) since I have no webviews in my app.

How can I isolate and determinate if is an error I introduced or a bug in the SDK?

Addev
  • 31,819
  • 51
  • 183
  • 302

2 Answers2

0

Only UIThread can handle the views (ui), so try to use this code to notify your app UI

runOnUiThread(new Runnable() {
 @Override
 public void run() { // add your code here 
}});

Or you can use the AsyncTask

Developer So far
  • 353
  • 1
  • 11
0

This error occur when you try to update a UI view in a background thread. Make sure you are not updating any view in your background thread like edit text, text view etc. Update your views in a UI thread. See this for example.

Community
  • 1
  • 1
Nouman Ghaffar
  • 3,780
  • 1
  • 29
  • 37