How to prevent Android GreedoLayout Out

How do you prevent Greedo from accessing index which is out-of-bounds ?

The following is the stack trace:

--------- beginning of crash

12-28 17:19:22.338 8668-8668/com.pixerf.android E/AndroidRuntime: FATAL EXCEPTION: main Process: com.pixerf.android, PID: 8668 java.lang.IndexOutOfBoundsException: Index: 56, Size: 56 at java.util.ArrayList.get(ArrayList.java:411) at com.fivehundredpx.greedolayout.GreedoLayoutSizeCalculator.sizeForChildAtPosition(GreedoLayoutSizeCalculator.java:71) at com.fivehundredpx.greedolayout.GreedoLayoutManager.sizeForChildAtPosition(GreedoLayoutManager.java:282) at com.fivehundredpx.greedolayout.GreedoLayoutManager.preFillGrid(GreedoLayoutManager.java:206) at com.fivehundredpx.greedolayout.GreedoLayoutManager.onLayoutChildren(GreedoLayoutManager.java:122) at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3719) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3436) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3988) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at a ndroid.support.v4.widget.SwipeRefreshLayout.onLayout(SwipeRefreshLayout.java:611) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1079) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1769) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:132) at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42) at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1361) at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:874) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup .java:5612) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585) at android.widget.LinearLayout.onLayout(LinearLayout.java:1494) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585) at android.widget.LinearLayout.onLayout(LinearLayout.java:1494) at android.view.View.layout(V iew.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at com.android.internal.policy.DecorView.onLayout(DecorView.java:724) at android.view.View.layout(View.java:17523) at android.view.ViewGroup.layout(ViewGroup.java:5612) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2342) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2069) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871) at android.view.Choreographer.doCallbacks(Choreographer.java:683) at android.view.Choreographer.doFrame(Choreographer.java:619) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857) at android.os.Handler.handleCallback(Handler.java:751) 12-28 17:19:22. 339 8668-8668/com.pixerf.android E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6077) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)


检查你的数组列表或数组大小,然后完成你的任务

if(arraylist.size()>0)
{
//do something 
} 
链接地址: http://www.djcxy.com/p/93170.html

上一篇: 如何在Android中播放音频文件?

下一篇: 如何防止Android GreedoLayout输出