GreenRobot's eventbus can't see annotation, "no public methods"
Asked Answered
C

1

8

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

Coloring answered 8/2, 2016 at 16:37 Comment(0)
C
10

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".

Coloring answered 9/2, 2016 at 15:2 Comment(1)
For me it was because of ProGuard. Fix was here: greenrobot.org/eventbus/documentation/proguardKlemens

© 2022 - 2024 — McMap. All rights reserved.