snackbarmanaegr无法检测适配器中的活动

时间:2015-12-23 07:24:37

标签: android snackbar

在我的滑动适配器中使用snackbarmanager时出现错误,如下所示:

  

12-23 10:53:18.298 5285-5285 / com.tosa.university E / SnackbarManager:无法从Snackbar的上下文中获取活动。尝试调用#show(Snackbar,Activity)   java.lang.ClassCastException:com.tosa.university.AppController无法强制转换为android.app.Activity                                                                           在com.nispok.snackbar.SnackbarManager.show(SnackbarManager.java:36)                                                                           at com.tosa.university.SampleAdapter.onSwipe(SampleAdapter.java:209)                                                                           在com.tr4android.recyclerviewslideitem.SwipeAdapter $ 1.onSwipeRight(SwipeAdapter.java:56)                                                                           在com.tr4android.recyclerviewslideitem.SwipeItem.dispatchOnSwipeRight(SwipeItem.java:325)                                                                           at com.tr4android.recyclerviewslideitem.SwipeItem $ DragHelperCallback.onViewDragStateChanged(SwipeItem.java:389)                                                                           在android.support.v4.widget.ViewDragHelper.setDragState(ViewDragHelper.java:874)                                                                           在android.support.v4.widget.ViewDragHelper $ 2.run(ViewDragHelper.java:335)                                                                           在android.os.Handler.handleCallback(Handler.java:739)                                                                           在android.os.Handler.dispatchMessage(Handler.java:95)                                                                           在android.os.Looper.loop(Looper.java:135)                                                                           在android.app.ActivityThread.main(ActivityThread.java:5272)                                                                           at java.lang.reflect.Method.invoke(Native Method)                                                                           在java.lang.reflect.Method.invoke(Method.java:372)                                                                           在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:909)                                                                           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)

1 个答案:

答案 0 :(得分:0)

根据错误日志:

  

java.lang.ClassCastException:com.tosa.university.AppController不能   被强制转换为android.app.Activity

您的问题是因为使用了错误的Context而不是Activity Context。更改mContext初始化以在SwipeAdapter中获得正确的Activity上下文。