带有 Fragment 的 NullPointerException eventbus subcribe 方法

NullPointerException eventbus subcribe method with Fragment

提问人:talhafaki 提问时间:4/19/2021 最后编辑:leeJBtalhafaki 更新时间:4/20/2021 访问量:99

问:

我调用 in 并将其与 fragment 中的 subscribe 方法一起使用,但我删除了 syntetic,它仍然给出 kotlin nullpointer 错误。EventBusViewPager.Scroll_State_Dragging

错误信息:

Caused by: java.lang.NullPointerException: at com.myproject.ui.fragment.MyFragment.onMyEvent (MyFragment.java:93)

MyFragment.java:93 -> binding.textView.text = "worked"

源代码:

class MyEvent
EventBus.getDefault().post(MyEvent())
@Subscribe
fun onMyEvent(e: MyEvent?) {
 binding.textView.text = "worked"
}
android kotlin android-fragments nullpointerexception greenrobot-eventbus

评论


答:

0赞 Yusuf Tezcan 4/19/2021 #1

EventBus.getDefault().register(“此处的活动名称”)

评论

0赞 talhafaki 4/19/2021
BaseActivity içerisinde register etmiştim zaten, aynı class içerisinde bulunan subscribe methodlarında crash yaşanmıyor.Bu methodda yaşanıyor sadece.