Home » Android » java – GreenRobot's eventbus can't see annotation, "no public methods"

java – GreenRobot's eventbus can't see annotation, "no public methods"

Posted by: admin June 15, 2020 Leave a comment

Questions:

So, I found out about Green Robots’ eventbus module. Followed the instructions on this page to try to get it working:
http://greenrobot.org/eventbus/documentation/how-to-get-started/

Seems simple enough.

I put in the appropriate code, but when run on device I get a crash:

org.greenrobot.eventbus.EventBusException: Subscriber class com.crowdlab.activities.LoadingActivity and its super classes have no public methods with the @Subscribe annotation.

The first few lines of my class look like this:

public class LoadingActivity extends BaseActivity implements AlertDialogButtonListener {
    AlertDialog mDialog = null;
    AlertDialog mPushDialog = null;

    @Subscribe
    public void onMessageEvent(MessageEvent event){
        Toast.makeText(this, "From Loading "+event.message, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onStart() {
        super.onStart();
        EventBus.getDefault().register(this);
    }

    @Override
    public void onStop() {
        EventBus.getDefault().unregister(this);
        super.onStop();
    }
    .
    .
    .

It /seems/ the annotation is there. The compile happens without so much as a warning. I’m using version 3.0.0 as specified in the gradle file…

So what could be wrong? (RTFM gratefully accepted, just tell where the FM with a relevant article is.)

Thanks!

-Ken

How to&Answers:

Doh! I chose Google’s @Subscribe rather than Green Robot’s.

import com.google.common.eventbus.Subscribe;

rather than

import org.greenrobot.eventbus.Subscribe;

The error should probably read “no method’s implementing the com.greenrobot.eventbus @Subscribe annotation”.