IndexOutOfBoundsException in RecyclerView triggered
on runOnUiThread(new Runnable()
錯誤訊息
FATAL EXCEPTION: main java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 8(offset:8).state:9
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4405)
android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
android.support.v7.widget.GridLayoutManager.layoutChunk(GridLayoutManager.java:458)
android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:562)
android.support.v7.widget.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:171)
Code內容大致上
public BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public synchronized void onLeScan(final BluetoothDevice device, final int rssi, final byte[] scanRecord) {
runOnUiThread(new Runnable() {
@Override
public void run() {
synchronized (this) {
String deviceName = device.getName();
if (XXX) {
XXX
} else {
XXX
}
mRecyclerView_RollCall.postDelayed(new Runnable() {
@Override
public void run() {
mRecyclerViewAdapter.notifyDataSetChanged();
}
}, 1000);
}
}
});
}
};
找過的一些Solution
https://code.google.com/p/android/issues/detail?id=77846
https://code.google.com/p/android/issues/detail?id=77232
我有找了很多Solution不過沒辦法解決問題,麻煩懂得大大可以給點建議!
很多大部分是,下拉刷新,不過我是需要一直更新RecyclerView上的item,
增加或是刪除item已經有另一個線程用ArrayList做了,一開始都可以正常的使用,
過一下後,就會出現這個Excetion!