美文网首页Android
StaggeredGridLayoutManager报错Inde

StaggeredGridLayoutManager报错Inde

作者: 龙猫跑跑跑 | 来源:发表于2016-06-12 12:15 被阅读1037次
    E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: co.netlong.skyoto, PID: 26079
                  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 android.support.v7.widget.StaggeredGridLayoutManager$Span.calculateCachedStart(StaggeredGridLayoutManager.java:2357)
                      at android.support.v7.widget.StaggeredGridLayoutManager$Span.getStartLine(StaggeredGridLayoutManager.java:2374)
                      at android.support.v7.widget.StaggeredGridLayoutManager.checkSpanForGap(StaggeredGridLayoutManager.java:396)
                      at android.support.v7.widget.StaggeredGridLayoutManager.hasGapsToFix(StaggeredGridLayoutManager.java:345)
                      at android.support.v7.widget.StaggeredGridLayoutManager.checkForGaps(StaggeredGridLayoutManager.java:272)
                      at android.support.v7.widget.StaggeredGridLayoutManager.onScrollStateChanged(StaggeredGridLayoutManager.java:307)
                      at android.support.v7.widget.RecyclerView.dispatchOnScrollStateChanged(RecyclerView.java:3977)
                      at android.support.v7.widget.RecyclerView.setScrollState(RecyclerView.java:1219)
                      at android.support.v7.widget.RecyclerView.access$3900(RecyclerView.java:147)
                      at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:4128)
                      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
                      at android.view.Choreographer.doCallbacks(Choreographer.java:590)
                      at android.view.Choreographer.doFrame(Choreographer.java:559)
                      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
                      at android.os.Handler.handleCallback(Handler.java:739)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:145)
                      at android.app.ActivityThread.main(ActivityThread.java:5835)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at java.lang.reflect.Method.invoke(Method.java:372)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
    

    使用viewpager+4个fragment

    每个fragment中为swiperefreshlayout+recyclerview

    出现上述错误,最终错误原因不在StaggeredGridLayoutManager,而是viewpager的状态保存

    解决方法:
    viewpager.setOffscreenPageLimit(list.size() - 1);

    相关文章

      网友评论

        本文标题:StaggeredGridLayoutManager报错Inde

        本文链接:https://www.haomeiwen.com/subject/zqmedttx.html