既然开通了博客,就写写吧,虽然我是个懒人,EventBus报错--懒人笔记01

今天见到群里有人问到EventBus修改UI的时候报的错误,日志为:

android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

他写的原始代码为:

@Subscribe

public void onEventMainThread(MessageEvent event){
//处理代码
}

解决方法:

@Subscribe加上(threadMode = ThreadMode.MAIN)就可以了,最后这样:

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(MessageEvent event){
//处理代码
}

好了,第一篇懒人笔记就这样吧,往后慢慢整理.


你可能感兴趣的:(android日常错误)