是谁让你在子线程更新UI的?android.view.ViewRootImpl$CalledFromWrongThreadException

2022-05-09 10:35:02 浏览数 (1)

飞哥语录:如果你想改变生活,首先就应该改变自己。

在使用EventBus时报如下异常:

代码语言:javascript复制
E/EventBus: Could not dispatch event: class com.model.EventBusMsg to subscribing class class com.anloq.activity.SettingActivity
                                                           android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
                                                               at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6096)
                                                               at android.view.ViewRootImpl.requestLayout(ViewRootImpl.java:824)

上面大致说的意思是EventBus再设置处理UI时只能在UI线程中,我使用的是 BACKGROUND

解决办法:

  1. 改为 MAIN
  2. 处理UI时加上runOnUiThread即可;

最后,希望对你有帮助!

0 人点赞