BelooS / ChipsLayoutManager

ANDROID. ChipsLayoutManager (SpanLayoutManager, FlowLayoutManager). A custom layout manager for RecyclerView which mimicric TextView span behaviour, flow layouts behaviour with support of amazing recyclerView features
Apache License 2.0
3.25k stars 362 forks source link

IllegalArgumentException: you can't move above of maxItemCount #34

Open csbenz opened 7 years ago

csbenz commented 7 years ago

I'm getting the following error from users on many api's and many different devices. Any idea why?

Fatal Exception: java.lang.IllegalArgumentException: you can't move above of maxItemCount
       at com.beloo.widget.chipslayoutmanager.layouter.AbstractPositionIterator.move(AbstractPositionIterator.java:17)
       at com.beloo.widget.chipslayoutmanager.ChipsLayoutManager.fillWithLayouter(ChipsLayoutManager.java:852)
       at com.beloo.widget.chipslayoutmanager.ChipsLayoutManager.fill(ChipsLayoutManager.java:815)
       at com.beloo.widget.chipslayoutmanager.ChipsLayoutManager.onLayoutChildren(ChipsLayoutManager.java:719)
       at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3583)
       at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3025)
       at android.view.View.measure(View.java:18799)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1458)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:746)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
       at android.view.View.measure(View.java:18799)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:18799)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:898)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
       at android.view.View.measure(View.java:18799)
       at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1658)
       at android.view.View.measure(View.java:18799)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:898)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
       at android.view.View.measure(View.java:18799)
       at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
       at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
       at android.view.View.measure(View.java:18799)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:18799)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
       at android.view.View.measure(View.java:18799)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:18799)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at android.view.View.measure(View.java:18799)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1458)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:746)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)
       at android.view.View.measure(View.java:18799)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
       at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2899)
       at android.view.View.measure(View.java:18799)
       at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2108)
       at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1224)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1460)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1115)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6023)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
       at android.view.Choreographer.doCallbacks(Choreographer.java:670)
       at android.view.Choreographer.doFrame(Choreographer.java:606)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
       at android.os.Handler.handleCallback(Handler.java:739)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5461)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
qmetzler-luna commented 7 years ago

Just came across the same crash. Did you find a clue on where to look?

csbenz commented 7 years ago

@qmetzler-luna Unfortunately not

corvinav commented 7 years ago

Have the same problem. Did you find solution?

corvinav commented 7 years ago

OMG this works for me: <android.support.v7.widget.RecyclerView android:id="@+id/chips_recycler" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingTop="8dp" android:paddingBottom="8dp" /> this doesn't work: <android.support.v7.widget.RecyclerView android:id="@+id/chips_recycler" android:layout_width="match_parent" android:layout_height="match_parent" />

wanGiB commented 7 years ago

Having same issue here. Please who managed to find a solution to this?

wanGiB commented 7 years ago

Ok. I think I found a work around on this.

I basically opened the AbstractPositionIterator.java file and rewrote the move method from

public void move(@IntRange(from = 0) int pos) { if (pos >= itemCount) throw new IllegalArgumentException("you can't move above of maxItemCount"); if (pos < 0) throw new IllegalArgumentException("can't move to negative position"); this.pos = pos; }

to

public void move(@IntRange(from = 0) int pos) { if (pos >= itemCount) { pos = itemCount; } if (pos < 0) throw new IllegalArgumentException("can't move to negative position"); this.pos = pos; }

and that fixed it for me.

alexjiexiaoqi commented 6 years ago

it sames that the pos belong to the previous data. For example, you put datas which size is 20, and scroll it to the bottom, so the current pos is 20, but now you want to update the recycleview, you put another datas which size is 10, so the pos 20 is big than 10. so you'd betther scroll the recycleview to the start positon.

public void setDatas(List list) { /* first scroll current pos to 0, then change the datas to update recycleview / recyclerView.scrollToPosition(0); datas = list; mAdapter.setData(datas); }

Pradeepkumar2091 commented 6 years ago

having the same problem.

This issue occurs, when first-time data added to list and then immediately cleared, After clearing data list then again adding data to list.

How can I fix this issue?

gipson1001 commented 5 years ago

I place recyclerview in NestedScrollView to fix it, you can try

AmritpalSingh5 commented 5 years ago

Just setAdapter() every time instead of notifyDataSetChange() . it solved my crash.

JaydipRadadiya commented 4 years ago

Just setAdapter() every time instead of notifyDataSetChange() . it solved my crash.

Thank you @AmritpalSingh5 it working perfectly!!