java - 无法发送事件错误

标签 java android android-event

我是 android 的新手,正在开发 app.help me in this.My Log is here

  Could not dispatch event: class com.shalom.shalombase.event.RequestPurchaseEvent to handler [EventHandler public void com.shalom.shalombase.activity.MainActivity.onRequestPurchaseEvent(com.shalom.shalombase.event.RequestPurchaseEvent)]: null
        at com.squareup.otto.Bus.throwRuntimeException(Bus.java:456)
        at com.squareup.otto.Bus.dispatch(Bus.java:386)
        at com.squareup.otto.Bus.dispatchQueuedEvents(Bus.java:367)
        at com.squareup.otto.Bus.post(Bus.java:336)

正在向主 Activity 发布事件的 Myfragment subcriptionfragment。

  public class SubscribeFragment extends ShalomBaseFragment {


private Button subscribeLayout;
private LinearLayout subscribebuttonslayout;
private FrameLayout sampleframe;
private RelativeLayout subscribelayout;
View progressLayout;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    return inflater.inflate(R.layout.subscribe_layout, container, false);
}

@Subscribe
public void onStoreProgressEvent (StoreProgressEvent event) {

    if(event!=null&&progressLayout!=null)
    {

        if(event.isInProgress)
            progressLayout.setVisibility(View.VISIBLE);
        else
            progressLayout.setVisibility(View.GONE);

    }
}


@Override
public void onViewCreated(View view, Bundle savedInstanceState) {

    super.onViewCreated(view, savedInstanceState);
    initialize(view);

    subscribebuttonslayout.setVisibility(View.VISIBLE);
    subscribelayout.setVisibility(View.VISIBLE);

    subscribeLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            bus.post(new RequestPurchaseEvent(BaseConstants.YEARLY_SUBSCRIPTION));

        }
    });

    getChildFragmentManager().beginTransaction()
            .replace(R.id.sample_frame, new LibrarySamleIssueFragment())
            .commit();



 }

private void initialize(View view) {

    subscribeLayout = (Button) view.findViewById(R.id.button1);
    subscribebuttonslayout = (LinearLayout) view.findViewById(R.id.subscribe_buttons_layout);
    sampleframe = (FrameLayout) view.findViewById(R.id.sample_frame);
    progressLayout = (View) view.findViewById(R.id.progress_layout);
    subscribelayout = (RelativeLayout) view.findViewById(R.id.subscribe_layout);
}



  }

请帮我解决这个问题。它在 S3 上运行良好,但在 Nexus7 上却产生了问题。 我不知道代码有什么问题。我对此感到困惑

最佳答案

代码:

method.invoke(target, event);

接下来的操作是:

@Subscribe
public void yourMethod(Event event) {
    //your code throw exception
}

你的方法抛出异常被otto捕获

所以,这就是我的条件。

关于java - 无法发送事件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27675608/

相关文章:

java - 当我想在 Activity 中获取字符串时,我得到 NULL

Android:设置部分背景

android - 如何检测点击事件是否在android中完成?

Android:处理 onClickListener 时出错

Java 泛型上限通配符限制

java - 为什么 ClassLoader.getResource ("/pkg/readme.txt")总是返回 null 且资源名称带有前导斜杠?

java - 新关键字和垃圾收集

android - 图片 View : image change animation

java - Android 开发 - GestureDetector.OnGestureListener 或 GestureDetector.SimpleOnGestureListener

java - Velocity:如何定义全局变量