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

时间:2016-02-08 16:37:35

标签: 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.

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

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感激地接受了,只是告诉调频与相关文章的位置。)

谢谢!

-Ken

1 个答案:

答案 0 :(得分:9)

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

public static void main( String[] args ) throws Exception {
    JFileChooser fc = new JFileChooser();
    int returnVal = fc.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        App.file = fc.getSelectedFile();
        //This is where a real application would open the file.
        System.out.println("Opening: " + App.file.getName() + ".");
    } else {
        System.out.println("Open command cancelled by user.");
    }       


    workbook = Workbook.getWorkbook(App.file);
      Sheet sheet = workbook.getSheet(1);

      Cell cell1 = sheet.getCell(4, 27);
      System.out.println(cell1.getContents());
      Cell cell2 = sheet.getCell(4, 28);
          System.out.println(cell11.getContents());




      App.eStop = false;
     int i = 0 ;
    while (App.eStop == false) {
         try {


          cell3 = sheet.getCell(9, i);
          System.out.println(cell3.getContents());  
         } catch (Exception e) {
             App.eStop = true; 
         };
        i++;


    }


    System.out.println("done");

而不是

psess.GetPS().SendKeys(cell1.getContents(), 8, 18);

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