nilsbraden / ttrss-reader-fork

An Android-Client for the self-hosted Tiny Tiny RSS feedreader
https://www.nilsbraden.de/TTRSS-Reader/
151 stars 40 forks source link

CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. #349

Closed lingling-fan closed 3 years ago

lingling-fan commented 7 years ago

//package name: org.ttrssreader //version: 1.91.1 java.lang.RuntimeException: An error occured while executing doInBackground() at org.ttrssreader.utils.AsyncTask$3.done(Unknown Source) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352) at java.util.concurrent.FutureTask.setException(FutureTask.java:219) at java.util.concurrent.FutureTask.run(FutureTask.java:239) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:841) Caused by: android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:5908) at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:837) at android.view.View.requestLayout(View.java:15792) at android.view.View.requestLayout(View.java:15792) at android.view.View.requestLayout(View.java:15792) at android.view.View.requestLayout(View.java:15792) at android.view.View.requestLayout(View.java:15792) at android.view.View.requestLayout(View.java:15792) at android.view.View.requestLayout(View.java:15792) at android.view.View.requestLayout(View.java:15792) at android.view.View.setFlags(View.java:8584) at android.view.View.setVisibility(View.java:5830) at android.widget.ProgressBar.setVisibility(ProgressBar.java:930) at org.ttrssreader.gui.MenuActivity.setSupportProgressBarIndeterminateVisibility(Unknown Source) at org.ttrssreader.controllers.ProgressBarManager.setIndeterminateVisibility(Unknown Source) at org.ttrssreader.controllers.ProgressBarManager.addProgress(Unknown Source) at org.ttrssreader.gui.MenuActivity.doCache(Unknown Source) at org.ttrssreader.gui.MenuActivity.access$000(Unknown Source) at org.ttrssreader.gui.MenuActivity$ImageCacheUpdater.update(Unknown Source) at org.ttrssreader.model.updaters.Updater.doInBackground(Unknown Source) at org.ttrssreader.model.updaters.Updater.doInBackground(Unknown Source) at org.ttrssreader.utils.AsyncTask$2.call(Unknown Source) at java.util.concurrent.FutureTask.run(FutureTask.java:234)

lingling-fan commented 7 years ago

Note: Update() calls and reaches addProgress(), and then SetIndeterminateVisibility(), and modify the UI. Description: The view is initialized or changed in the main UI thread, but if another thread update this view, the exception may be thrown. Fix solution:

  1. update the UI in a UI thread, call Activity#runOnUiThread(...)
  2. move code to 'OnPreExecute' or 'OnPostExecute'