【问题标题】:GreenRobot's eventbus can't see annotation, "no public methods"GreenRobot 的 eventbus 看不到注解,“没有公共方法”
【发布时间】:2016-02-08 16:37:35
【问题描述】:

所以,我发现了 Green Robots 的事件总线模块。按照此页面上的说明尝试使其正常工作: http://greenrobot.org/eventbus/documentation/how-to-get-started/

看起来很简单。

我输入了适当的代码,但在设备上运行时出现崩溃:

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

我班级的前几行如下所示:

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();
    }
    .
    .
    .

它/似乎/注释在那里。编译在没有任何警告的情况下发生。我正在使用 gradle 文件中指定的 3.0.0 版本...

那么可能出了什么问题? (RTFM 欣然接受,只要说出相关文章的 FM 在哪里。)

谢谢!

-肯

【问题讨论】:

    标签: java android annotations event-bus greenrobot-eventbus


    【解决方案1】:

    哇!我选择了 Google 的 @Subscribe 而不是 Green Robot。

    import com.google.common.eventbus.Subscribe;
    

    而不是

    import org.greenrobot.eventbus.Subscribe;
    

    错误可能应该是“没有方法实现 com.greenrobot.eventbus @Subscribe 注释”。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多