调用onItemSelected()方法时出现此错误,这个错误意味着什么?也许您有任何想法如何解决?
在MainActivity中调用的方法
@Override
public void onAdviceBodyItemSelected(Advice advice) {
SideEffectReportActivity.start(this, advice);
}
接口
public interface MainRouter extends BodyRouter {
void onAdviceBodyItemSelected(Advice advice);
}
, 片段
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
MainActivity activity = (MainActivity) getActivity();
getPresenter().setRouter(activity);
mAdvicePresenter.getList(mBody);
activity.resolveToolbar(this);
}
, 演示者课程
public class AdviceListPresenter extends BasePresenter<AdviceListView,`
MainRouter> {
private static final String TAG = "advicelistpresenter";
private
final GetSideEffectListByCategoryInteractor mGetSideEffectListInteractor;
@Inject
AdviceListPresenter(GetSideEffectListByCategoryInteractor getSideEffectListInteractor) {
mGetSideEffectListInteractor = getSideEffectListInteractor;
}
@Override public void onStart() {
}
@Override public void onStop() {
mGetSideEffectListInteractor.unsubscribe();
}
void getList(Body body) {
getView().onStartLoading();
mGetSideEffectListInteractor.execute(body.name(), new Subscriber<List<Advice>>() {
@Override public void onCompleted() {
}
@Override public void onError(Throwable e) {
getView().onLoaded();
}
@Override public void onNext(List<Advice> groups) {
getView().onLoaded();
System.out.println("----------------------------------------------------------qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq--------------------------------: ");
getView().updateAList(groups);
}
});
}
void onItemSelected(Advice advice) {
// getRouter().openSideEffect(advice);
//getRouter().onAdviceItemSelected(advice);
// Log.e(TAG," ADVICE :" + advice.bodypartProblemsGroup);
Log.e(TAG,"router :" + getRouter());
getRouter().onAdviceBodyItemSelected(advice);
}
void onGItemSelected(AdviceGroup adviceGroup) {
// getRouter().openSideEffect(advice);
//getRouter().onAdviceItemSelected(advice);
// Log.e(TAG," ADVICE :" + advice.bodypartProblemsGroup);
}
}
致命的例外:主要 处理:com.ct.rrapp,PID:15838 java.lang.ClassCastException:com.ct.rrapp.presentation.side_Effect.SideEffectReportActivity无法强制转换为nl.creativeict.radiotherapp.presentation.main.MainRouter at com.ct.rrapp.presentation.side_Effect.advice_list.AdviceListPresenter.onItemSelected(AdviceListPresenter.java:80) at com.ct.rrapp.presentation.side_Effect.advice_list.AdviceListFragment $ 1.onItemSelected(AdviceListFragment.java:93) 在com.ct.rrapp.presentation.side_Effect.advice_list.common.AdviceListAdapter.lambda $ onBindViewHolder $ 1(AdviceListAdapter.java:55) at com.ct.rrapp.presentation.side_Effect.advice_list.common.AdviceListAdapter $$ Lambda $ 4.onClick(Unknown Source) 在android.view.View.performClick(View.java:5697) 在android.view.View $ PerformClick.run(View.java:22526) 在android.os.Handler.handleCallback(Handler.java:739) 在android.os.Handler.dispatchMessage(Handler.java:95) 在android.os.Looper.loop(Looper.java:158) 在android.app.ActivityThread.main(ActivityThread.java:7224) at java.lang.reflect.Method.invoke(Native Method) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1230) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
答案 0 :(得分:1)
从这条线来判断:
@Override
public void onAdviceBodyItemSelected(Advice advice) {
SideEffectReportActivity.start(this, advice);
}
此异常消息:
java.lang.ClassCastException:SideEffectReportActivity无法强制转换为MainRouter
可以得出结论,静态方法SideEffectReportActivity#start(*, Advice)
期望MainRouter
作为第一个参数,而this
对象是实例的类不实现MainRouter
接口。
如果this
对象是MainActivity
的实例,则表示您的活动未实现MainRouter
。