lucasr / twoway-view

[DEPRECATED] RecyclerView made simple
5.23k stars 1.02k forks source link

ArrayIndexOutOfBoundsException thrown when calling SpannableLayoutAdapter.removeItem( 0 ) #242

Open bemusementpark opened 8 years ago

bemusementpark commented 8 years ago

I added a click listener to the demo that removes the element you clicked. All elements seem to be removable except the first element, element 0.

I added a handler to postpone the removeItem call, perhaps after the click is finished being handled, but the error is the same.

 java.lang.ArrayIndexOutOfBoundsException: length=22; index=-1
    E      at org.lucasr.twowayview.widget.ItemEntries.putItemEntry(ItemEntries.java:74)
    E      at org.lucasr.twowayview.widget.BaseLayoutManager.setItemEntryForPosition(BaseLayoutManager.java:208)
    E      at org.lucasr.twowayview.widget.SpannableGridLayoutManager.cacheChildLaneAndSpan(SpannableGridLayoutManager.j
                            ava:229)
    E      at org.lucasr.twowayview.widget.BaseLayoutManager.measureChild(BaseLayoutManager.java:474)
    E      at org.lucasr.twowayview.TwoWayLayoutManager.setupChild(TwoWayLayoutManager.java:461)
    E      at org.lucasr.twowayview.TwoWayLayoutManager.fillFromScrapList(TwoWayLayoutManager.java:449)
    E      at org.lucasr.twowayview.TwoWayLayoutManager.onLayoutScrapList(TwoWayLayoutManager.java:740)
    E      at org.lucasr.twowayview.widget.BaseLayoutManager.onLayoutScrapList(BaseLayoutManager.java:375)
    E      at org.lucasr.twowayview.TwoWayLayoutManager.onLayoutChildren(TwoWayLayoutManager.java:727)
    E      at org.lucasr.twowayview.widget.BaseLayoutManager.onLayoutChildren(BaseLayoutManager.java:369)
    E      at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:1918)
    E      at android.support.v7.widget.RecyclerView.resumeRequestLayout(RecyclerView.java:1101)
    E      at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:155)
    E      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
    E      at android.view.Choreographer.doCallbacks(Choreographer.java:574)
    E      at android.view.Choreographer.doFrame(Choreographer.java:543)
    E      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
    E      at android.os.Handler.handleCallback(Handler.java:733)
    E      at android.os.Handler.dispatchMessage(Handler.java:95)
    E      at android.os.Looper.loop(Looper.java:136)
    E      at android.app.ActivityThread.main(ActivityThread.java:5118)
    E      at java.lang.reflect.Method.invokeNative(Native Method)
    E      at java.lang.reflect.Method.invoke(Method.java:515)
    E      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
    E      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
    E      at dalvik.system.NativeStart.main(Native Method)
summers314 commented 7 years ago

Did you solve this?

summers314 commented 7 years ago

Solved.

This was crashy:

mItems.remove(position); notifyItemRemoved(position); notifyItemRangeChanged(position, mItems.size());

Change that to this:

mItems.remove(position); //notifyItemRemoved(position); //notifyItemRangeChanged(position, mItems.size()); notifyDataSetChanged();