Android - 在SwipeRefreshLayout加载时单击RecyclerView时崩溃

时间:2016-04-21 06:19:47

标签: android android-recyclerview swiperefreshlayout

我在RecyclerView内有SwipeRefreshLayout,当我重新加载页面时,加载SwipeRefreshLayout时,我点击了RecyclerView上的项目,然后崩溃了。

04-21 13:14:49.605 25586-25586/? E/AndroidRuntime: FATAL EXCEPTION: main
                                               Process: com.boxopen.funstack, PID: 25586
                                               java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
                                                   at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
                                                   at java.util.ArrayList.get(ArrayList.java:308)
                                                   at com.boxopen.funstack.adapter.RecycleBookAdapter$BookViewHolder.onClickLike(RecycleBookAdapter.java:339)
                                                   at com.boxopen.funstack.adapter.RecycleBookAdapter$BookViewHolder.access$100(RecycleBookAdapter.java:64)
                                                   at com.boxopen.funstack.adapter.RecycleBookAdapter$BookViewHolder$2.onDoubleClick(RecycleBookAdapter.java:122)
                                                   at com.boxopen.funstack.listener.DoubleClickListener.onClick(DoubleClickListener.java:36)
                                                   at android.view.View.performClick(View.java:4478)
                                                   at android.view.View$PerformClick.run(View.java:18698)
                                                   at android.os.Handler.handleCallback(Handler.java:733)
                                                   at android.os.Handler.dispatchMessage(Handler.java:95)
                                                   at android.os.Looper.loop(Looper.java:149)
                                                   at android.app.ActivityThread.main(ActivityThread.java:5268)
                                                   at java.lang.reflect.Method.invokeNative(Native Method)
                                                   at java.lang.reflect.Method.invoke(Method.java:515)
                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
                                                   at dalvik.system.NativeStart.main(Native Method)

04-21 13:14:49.675 182-1124 /? E / IMGSRV :: 0:PVRDRMOpen:TP3,ret = 57

3 个答案:

答案 0 :(得分:6)

根据我的理解,您的问题和日志基本上是清除arraylist中的onRefresh(),但不通知适配器列表已被清除。

请在清除notifyDataSetChanged()

后致电arraylist

答案 1 :(得分:1)

似乎您在刷新后清除了列表,但这些项目仍在您的recyclerview中。您应该立即通知您的适配器列表为空。 在您目前的情况下,开始滚动可能会导致应用程序崩溃?!

答案 2 :(得分:0)

你应该把条件检查大小(例如,数组,ArrayList ......你使用的)数据