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!