NullPointerException eventbus subcribe method with Fragment

120 Views Asked by At

I call the EventBus in ViewPager.Scroll_State_Dragging and use it with the subscribe method in fragment, but I removed the syntetic and it still gives the kotlin nullpointer error.

Error Message:

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

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

SourceCode:

class MyEvent
EventBus.getDefault().post(MyEvent())
@Subscribe
fun onMyEvent(e: MyEvent?) {
 binding.textView.text = "worked"
}
1

There are 1 best solutions below

1
On

EventBus.getDefault().register("Activity Name Here")