IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder異常處理
一般報這種錯誤有兩種情況:
第一種:list資料來源發生變化沒有及時重新整理adapter,也就是沒有及時notifyDataSetChanged()
第二種:以下情況的recycleView偶現錯誤,以下是第二種錯誤的解決方案
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{35b7b5f position=12 id=-1, oldPos=-1, pLpos:-1 no parent}
at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:5251)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5433)
at android.support.v7.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:270)
at android.support.v7.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:324)
at android.support.v7.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:337)
at android.support.v7.widget.GapWorker.prefetch(GapWorker.java:344)
at android.support.v7.widget.GapWorker.run(GapWorker.java:370)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:185)
at android.app.ActivityThread.main(ActivityThread.java:6493)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:916)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:806)
具體也沒有報哪一行出錯,最終還是要google大神去修復
臨時解決方案:
建立一個LinearLayoutManagerWrapper繼承LinearLayoutManager,重寫onLayoutChildren方法,加個異常處理就行了
public class WrapContentLinearLayoutManager extends LinearLayoutManager {
public WrapContentLinearLayoutManager(Context context) {
super(context);
}
public WrapContentLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
}
public WrapContentLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
//這裡加個異常處理 ,經測試可以避免閃退,具體副作用暫時還沒有發現,可以作為臨時解決方案
try {
super.onLayoutChildren(recycler, state);
} catch (IndexOutOfBoundsException e) {
e.printStackTrace();
}
}
}
然後recycleView中設定這個佈局就可以了,其他佈局樣式類似
mRecyclerView.setLayoutManager(new WrapContentLinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
相關文章
- Inconsistency detected Invalid view holder adapter position"ViewAPT
- RecyclerView基礎(一)Adapter與Holder的封裝之RvAdapter,RvHolderViewAPT封裝
- Layout Inflation :Unconditional layout, inflation from view adapterViewAPT
- [Oracle Script] latch holderOracle
- Dictionary inconsistency caused by CTAS in PARALLELParallel
- 查詢holder的操作
- Global Enqueue Services Deadlock detected.ENQ
- java.lang.IndexOutOfBoundsException: Index: 0, Size: 0JavaIndexException
- EXP-00006: internal inconsistency errorError
- Reliable Key Holder for Chastity Sub Anywhere in the WorldAST
- IM多型別holder封裝多型型別封裝
- 【Spring】java.lang.IndexOutOfBoundsException: Index: 256, Size: 256SpringJavaIndexException
- unexpected inconsistency;RUN fsck MANUALLY 解決方案
- flask資料庫遷移 No changes in schema detected.Flask資料庫
- AdapterAPT
- RecyclerView Adapter 系列(1):RecyclerView Array AdapterViewAPT
- 如何處理ABAP DDIC_TYPE_INCONSISTENCY錯誤
- IPC Send timeout detected. Receiver ospid 25822
- Adapter PatternAPT
- recycleView通用AdapterViewAPT
- 【Android Adapter】是時候開啟Adapter新時代了AndroidAPT
- RecyclerView Adapter 優雅封裝,一個Adapter搞定所有列表ViewAPT封裝
- design pattens - adapterAPT
- Adapter最佳實踐APT
- Oracle SOA Suite: AdapterOracleUIAPT
- JavaScript invalid 事件JavaScript事件
- Istio Mixer Adapter開發 (三)自定義Mixer Grpc Adapter部署APTRPC
- VirtualBox Host-only Adapter,Failed to create the host-only adapter 轉APTAI
- iOS 上架報錯 This bundle is invalid 或 Invalid Image PathiOS
- RecyclerView-->通用的AdapterViewAPT
- Androidlistview與adapter用法AndroidViewAPT
- ListView 通用 Adapter 封裝ViewAPT封裝
- 用例子來弄懂AdapterAPT
- 設計模式---Adapter模式設計模式APT
- ListView(2)——自定義AdapterViewAPT
- Disk arrary's adapter in troubleAPT
- 介面卡模式(Adapter)模式APT
- Adapter中getView的理解!APTView