GreenRobot的eventbus无法看到注释,"没有公共方法"

Ken*_*rey 8 java android annotations event-bus greenrobot-eventbus

所以,我发现了Green Robots的eventbus模块.按照此页面上的说明尝试使其正常工作: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.
Run Code Online (Sandbox Code Playgroud)

我班的前几行看起来像这样:

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();
    }
    .
    .
    .
Run Code Online (Sandbox Code Playgroud)

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

那可能是什么错?(RTFM感激地接受了,只是告诉调频与相关文章的位置.)

谢谢!

-Ken

Ken*_*rey 10

卫生署!我选择了谷歌的@Subscribe而不是绿色机器人.

import com.google.common.eventbus.Subscribe;
Run Code Online (Sandbox Code Playgroud)

而不是

import org.greenrobot.eventbus.Subscribe;
Run Code Online (Sandbox Code Playgroud)

错误应该是"没有方法实现com.greenrobot.eventbus @Subscribe注释".

  • 对我而言,这是因为ProGuard.修复在这里:http://greenrobot.org/eventbus/documentation/proguard/ (4认同)