Can't Repro
Status Update
Comments
al...@android.com <al...@android.com>
yb...@google.com <yb...@google.com> #2
I think this issue is already fixed internally, can you attach a sample app that I can use to test again?
go...@gmail.com <go...@gmail.com> #3
[Comment deleted]
go...@gmail.com <go...@gmail.com> #4
Unfortunately I spent the better half of the afternoon trying to replicate this on a simple app, but so far I have failed to do so.
Any ideas about when a new version of RV is coming out?
Any ideas about when a new version of RV is coming out?
go...@gmail.com <go...@gmail.com> #5
Actually, I don't need 2 view types. I can also trigger this with a single one. Now I'm using two adapters that work with the same ids / view holders and am using swapAdapter(). The getRecycledViewPool().clear() hack above doesn't work if recents is pressed and I come back to the app.
Demo:https://www.dropbox.com/s/5t3m6lq3ij4isjb/recyclerview_bug.mp4?dl=0
I can consistently reproduce that (ie. only crashing when I come back from recents and delete quickly).
The stacktrace is exactly the same as above.
Might this be related with using a android.widget.Filter and changing / notifying the adapter in publishResults()?
Demo:
I can consistently reproduce that (ie. only crashing when I come back from recents and delete quickly).
The stacktrace is exactly the same as above.
Might this be related with using a android.widget.Filter and changing / notifying the adapter in publishResults()?
zh...@gmail.com <zh...@gmail.com> #6
I'm facing the issue too, library version 22, log:
03-18 15:15:57.462: W/System.err(10102): java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{435debc0 position=2 id=-1, oldPos=1, pLpos:1 scrap tmpDetached not recyclable(1)undefined adapter position no parent}
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:3498)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3628)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3609)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1859)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1311)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1274)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:525)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2072)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.RecyclerView.resumeRequestLayout(RecyclerView.java:1231)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:207)
03-18 15:15:57.462: W/System.err(10102): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
03-18 15:15:57.462: W/System.err(10102): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
03-18 15:15:57.462: W/System.err(10102): at android.view.Choreographer.doFrame(Choreographer.java:543)
03-18 15:15:57.462: W/System.err(10102): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
03-18 15:15:57.462: W/System.err(10102): at android.os.Handler.handleCallback(Handler.java:733)
03-18 15:15:57.462: W/System.err(10102): at android.os.Handler.dispatchMessage(Handler.java:95)
03-18 15:15:57.462: W/System.err(10102): at android.os.Looper.loop(Looper.java:136)
03-18 15:15:57.462: W/System.err(10102): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-18 15:15:57.462: W/System.err(10102): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 15:15:57.462: W/System.err(10102): at java.lang.reflect.Method.invoke(Method.java:515)
03-18 15:15:57.462: W/System.err(10102): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-18 15:15:57.462: W/System.err(10102): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-18 15:15:57.462: W/System.err(10102): at dalvik.system.NativeStart.main(Native Method)
03-18 15:15:57.462: W/System.err(10102): java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{435debc0 position=2 id=-1, oldPos=1, pLpos:1 scrap tmpDetached not recyclable(1)undefined adapter position no parent}
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:3498)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3628)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3609)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1859)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1311)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1274)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:525)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2072)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.RecyclerView.resumeRequestLayout(RecyclerView.java:1231)
03-18 15:15:57.462: W/System.err(10102): at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:207)
03-18 15:15:57.462: W/System.err(10102): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
03-18 15:15:57.462: W/System.err(10102): at android.view.Choreographer.doCallbacks(Choreographer.java:574)
03-18 15:15:57.462: W/System.err(10102): at android.view.Choreographer.doFrame(Choreographer.java:543)
03-18 15:15:57.462: W/System.err(10102): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
03-18 15:15:57.462: W/System.err(10102): at android.os.Handler.handleCallback(Handler.java:733)
03-18 15:15:57.462: W/System.err(10102): at android.os.Handler.dispatchMessage(Handler.java:95)
03-18 15:15:57.462: W/System.err(10102): at android.os.Looper.loop(Looper.java:136)
03-18 15:15:57.462: W/System.err(10102): at android.app.ActivityThread.main(ActivityThread.java:5017)
03-18 15:15:57.462: W/System.err(10102): at java.lang.reflect.Method.invokeNative(Native Method)
03-18 15:15:57.462: W/System.err(10102): at java.lang.reflect.Method.invoke(Method.java:515)
03-18 15:15:57.462: W/System.err(10102): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
03-18 15:15:57.462: W/System.err(10102): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
03-18 15:15:57.462: W/System.err(10102): at dalvik.system.NativeStart.main(Native Method)
fe...@gmail.com <fe...@gmail.com> #7
For me, the problem was I wasn't clearing the user information stored on arrays. When I did a log out and tried to sing in again, it the arrays would still be populated. Clearing them on logout fixed my problem
[Deleted User] <[Deleted User]> #8
also got the crash: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{43ea2e18 position=3 id=-1, oldPos=-1, pLpos:-1 scrap tmpDetached no parent}
at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:3887)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4018)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3999)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1892)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1338)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1301)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:534)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2411)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:2709)
I haven't managed to reproduce it yet, it happens from time to time for no obvious reason.
at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:3887)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4018)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:3999)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1892)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1338)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1301)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:534)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2411)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:2709)
I haven't managed to reproduce it yet, it happens from time to time for no obvious reason.
a....@gmail.com <a....@gmail.com> #9
this was happening to me when I run the recyclerViewAdapter.notifyItemInserted on the main thread, while, at the same time there is insertion of adapter list in the background thread, which causes inconsistency between what indexes are being inserted, making the recyclerview confuses about this. For example, when the adapter list wants to insert an item at index 10, the UI thread notifies this insertion at 10, but, since the background thread is faster (from my case) that the UI thread, the background thread will insert another values, while at the same time the UI thread is still in notifying the recyclerview about the insertion. This is how I understood the situation (please tell if I am wrong at some point).
I solved the problem by having the adapter list insertion and notifyItemInserted both on the main thread.
I solved the problem by having the adapter list insertion and notifyItemInserted both on the main thread.
nc...@gmail.com <nc...@gmail.com> #10
Ok i solved this problem by Overriding android.support.v7.widget.LinearLayoutManager method onLayoutChildren like this :
public void onLayoutChildren(Recycler arg0, State arg1) {
try {
super.onLayoutChildren(arg0, arg1);
} catch (Exception e) {
Util.log("onLayoutChildren :" + e.toString());
}
}
public void onLayoutChildren(Recycler arg0, State arg1) {
try {
super.onLayoutChildren(arg0, arg1);
} catch (Exception e) {
Util.log("onLayoutChildren :" + e.toString());
}
}
yb...@google.com <yb...@google.com> #12
#9, thats the right solution. You cannot change adapter contents on a background thread.
#10, don't do that! Something else is wrong in your code that needs fixing and by doing that, you are leaving RecyclerView in an inconsistent state, it is very likely that RV will keep crashing from then on because it lost its state.
#10, don't do that! Something else is wrong in your code that needs fixing and by doing that, you are leaving RecyclerView in an inconsistent state, it is very likely that RV will keep crashing from then on because it lost its state.
so...@gmail.com <so...@gmail.com> #13
#9, you are right.
at...@gmail.com <at...@gmail.com> #14
#9 Could you please provide a solution as you have resolved by "having the adapter list insertion and notifyItemInserted both on the main thread."
mk...@gmail.com <mk...@gmail.com> #15
[Comment deleted]
mk...@gmail.com <mk...@gmail.com> #16
my solution
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("unused")
public abstract class MRecyclerViewAdapter<Entity, ViewHolder extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<ViewHolder>{
protected Context context;
protected List<Entity> dataList;
public MRecyclerViewAdapter(Context context, List<Entity> dataList) {
setContext(context);
setDataList(dataList);
}
public Context getContext() {
return context;
}
public List<Entity> getDataList() {
if (dataList == null)
dataList = new ArrayList<>();
return dataList;
}
protected void setContext(Context context) {
this.context = context;
}
protected void setDataList(List<Entity> dataList) {
this.dataList = dataList;
}
@Override
public int getItemCount() {
return dataList.size();
}
public void remove(int position) {
if (position > 0 && position < getDataList().size()) {
getDataList().remove(position);
notifyItemRemoved(position);
}
}
public void removeAll() {
int oldSize = getDataList().size();
getDataList().clear();
notifyItemRangeRemoved(0, oldSize);
}
public void add(List<Entity> newList) {
if (newList != null && !newList.isEmpty()) {
int oldSize = getDataList().size();
getDataList().addAll(newList);
notifyItemRangeChanged(oldSize - 1, newList.size());
}
}
public void add(Entity entity, int position) {
if (position > 0 && position <= getDataList().size()) {
getDataList().add(entity);
notifyItemInserted(position);
}
}
public void notifyItemRangeChanged() {
notifyItemRangeChanged(0, getDataList().size());
}
}
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
@SuppressWarnings("unused")
public abstract class MRecyclerViewAdapter<Entity, ViewHolder extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<ViewHolder>{
protected Context context;
protected List<Entity> dataList;
public MRecyclerViewAdapter(Context context, List<Entity> dataList) {
setContext(context);
setDataList(dataList);
}
public Context getContext() {
return context;
}
public List<Entity> getDataList() {
if (dataList == null)
dataList = new ArrayList<>();
return dataList;
}
protected void setContext(Context context) {
this.context = context;
}
protected void setDataList(List<Entity> dataList) {
this.dataList = dataList;
}
@Override
public int getItemCount() {
return dataList.size();
}
public void remove(int position) {
if (position > 0 && position < getDataList().size()) {
getDataList().remove(position);
notifyItemRemoved(position);
}
}
public void removeAll() {
int oldSize = getDataList().size();
getDataList().clear();
notifyItemRangeRemoved(0, oldSize);
}
public void add(List<Entity> newList) {
if (newList != null && !newList.isEmpty()) {
int oldSize = getDataList().size();
getDataList().addAll(newList);
notifyItemRangeChanged(oldSize - 1, newList.size());
}
}
public void add(Entity entity, int position) {
if (position > 0 && position <= getDataList().size()) {
getDataList().add(entity);
notifyItemInserted(position);
}
}
public void notifyItemRangeChanged() {
notifyItemRangeChanged(0, getDataList().size());
}
}
pa...@gmail.com <pa...@gmail.com> #17
#9,where are you? where your solution?#16,it looks right,but not work for me!
om...@gmail.com <om...@gmail.com> #20
#17,
#9 means; just pay attention to all RV calls must be in same thread.
If you remove item from RV or add item to it, be sure your methods created in adapter and called everything from instance.
Especially the list you set to adapter and may u need to post UI actions from adapter's parentView.
Example;
---Adapter---
public void removeAt(int position) {
mList.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, mList.size());
}
public ArrayList<> getList() {
return mList;
}
---Fragment or Activity or another Adapter where you called it---
Adapter adapter = new Adapter(context, mData, new OnItemSelectOrDeleteListener() {
@Override
public void onItemSelected(final int position) {
doSomethingWithDataItem(adapter.getList().get(position))
}
@Override
public void onItemDeleted(final int position) {
parentView.post(new Runnable() {
@Override
public void run() {
adapter.removeAt(position);
}
});
}
});
I produced crash by myself and fixed via this way.
#9 means; just pay attention to all RV calls must be in same thread.
If you remove item from RV or add item to it, be sure your methods created in adapter and called everything from instance.
Especially the list you set to adapter and may u need to post UI actions from adapter's parentView.
Example;
---Adapter---
public void removeAt(int position) {
mList.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, mList.size());
}
public ArrayList<> getList() {
return mList;
}
---Fragment or Activity or another Adapter where you called it---
Adapter adapter = new Adapter(context, mData, new OnItemSelectOrDeleteListener() {
@Override
public void onItemSelected(final int position) {
doSomethingWithDataItem(adapter.getList().get(position))
}
@Override
public void onItemDeleted(final int position) {
parentView.post(new Runnable() {
@Override
public void run() {
adapter.removeAt(position);
}
});
}
});
I produced crash by myself and fixed via this way.
va...@gmail.com <va...@gmail.com> #21
Now I am using 27.0.2 and still not fixed. This is really very bad bug. 10 percent of users got affected.
go...@gmail.com <go...@gmail.com> #22
I'm also on 27.0.2 and getting this crash when calling notifyItemRangeInserted(0, newListSize);
ma...@gmail.com <ma...@gmail.com> #23
Same issue faced, but didn't provide solution from google side
na...@gmail.com <na...@gmail.com> #24
same issue faced, when i call SortedList.clear();
[Deleted User] <[Deleted User]> #25
go...@gmail.com <go...@gmail.com> #26
I am also got this same issue when clearing dataList
dataList.clear(); , very rare issue
dataList.clear(); , very rare issue
ma...@gmail.com <ma...@gmail.com> #27
Do we guys found any solution for this crash
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 2(offset:2).state:7829
We are getting this crash when we are loading 8000 contacts and scroll the view and do some operation like delete and add the contacts frequently.
If you guys have any solution please lets us know
Thanks In Advance
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 2(offset:2).state:7829
We are getting this crash when we are loading 8000 contacts and scroll the view and do some operation like delete and add the contacts frequently.
If you guys have any solution please lets us know
Thanks In Advance
hu...@gmail.com <hu...@gmail.com> #28
I am still got this error now. How to resolve this?
vi...@gmail.com <vi...@gmail.com> #29
#20 worked for me.
au...@google.com <au...@google.com>
[Deleted User] <[Deleted User]> #30
Using androidx.recyclerview:recyclerview:1.1.0 and still facing this issue.
WorkFLow: I am implementing an endless scroll with RecyclerView ( Detecting the end of the list and then loading more data)
1. When the screen opens for the first time, I fetch the data from the network and assign it to the adapter.
2. When the network call is in progress, I add a Loading item to the adapter list and remove that loading item once the API call is complete.
3. On reaching the end of the list, I call to load more data, which repeats the above step.
4. I am careful of doing all notify data adapter operations on the main thread.
But still, on some occasions this error pop-ups crashing the app.
WorkFLow: I am implementing an endless scroll with RecyclerView ( Detecting the end of the list and then loading more data)
1. When the screen opens for the first time, I fetch the data from the network and assign it to the adapter.
2. When the network call is in progress, I add a Loading item to the adapter list and remove that loading item once the API call is complete.
3. On reaching the end of the list, I call to load more data, which repeats the above step.
4. I am careful of doing all notify data adapter operations on the main thread.
But still, on some occasions this error pop-ups crashing the app.
[Deleted User] <[Deleted User]> #31
Updates: I read some threads regarding the same issue, seems like this occurs when
1. The adapter is updated in the background ---> I am not doing this
2. The Adapter list is modified, but the adapter is not correctly notified --> Quite Possible
I am adding all the items received from the network to the adapter list and then updating the adapter using notifyDataSetChanged.
1. The adapter is updated in the background ---> I am not doing this
2. The Adapter list is modified, but the adapter is not correctly notified --> Quite Possible
I am adding all the items received from the network to the adapter list and then updating the adapter using notifyDataSetChanged.
na...@gmail.com <na...@gmail.com> #32
Fatal Exception: java.lang.IndexOutOfBoundsException
Inconsistency detected. Invalid view holder adapter positiond{58c5840 position=1 id=-1, oldPos=2, pLpos:2 scrap [attachedScrap] tmpDetached no parent} androidx.recyclerview.widget.RecyclerView{358c63e VFED..... ......I. 0,0-978,1861 #7f0a07ba app:id/recycler}, adapter:hdvideoplayer.ui.videos.adapter.j@a5b9fd9, layout:androidx.recyclerview.widget.LinearLayoutManager@b277c9f, context:dagger.hilt.android.internal.managers.n@9c2b1ec
androidx.recyclerview.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition (RecyclerView.java:6544)
androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline (RecyclerView.java:6727)
androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:6688)
androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:6684)
androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next (LinearLayoutManager.java:2362)
androidx.recyclerview.widget.LinearLayoutManager.layoutChunk (LinearLayoutManager.java:1662)
androidx.recyclerview.widget.LinearLayoutManager.fill (LinearLayoutManager.java:1622)
androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren (LinearLayoutManager.java:687)
androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep1 (RecyclerView.java:4550)
androidx.recyclerview.widget.RecyclerView.dispatchLayout (RecyclerView.java:4305)
androidx.recyclerview.widget.RecyclerView.consumePendingUpdateOperations (RecyclerView.java:2065)
androidx.recyclerview.widget.RecyclerView$1.run (RecyclerView.java:438)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:1301)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:1309)
android.view.Choreographer.doCallbacks (Choreographer.java:923)
android.view.Choreographer.doFrame (Choreographer.java:847)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1283)
android.os.Handler.handleCallback (Handler.java:942)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loopOnce (Looper.java:226)
android.os.Looper.loop (Looper.java:313)
android.app.ActivityThread.main (ActivityThread.java:8757)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)
hi i got this error actually i have muilple viewtype in recycler and its loading ads two different types and one is item
also a grid view and linear view option
plz help how to resolve this crashe
Inconsistency detected. Invalid view holder adapter positiond{58c5840 position=1 id=-1, oldPos=2, pLpos:2 scrap [attachedScrap] tmpDetached no parent} androidx.recyclerview.widget.RecyclerView{358c63e VFED..... ......I. 0,0-978,1861 #7f0a07ba app:id/recycler}, adapter:hdvideoplayer.ui.videos.adapter.j@a5b9fd9, layout:androidx.recyclerview.widget.LinearLayoutManager@b277c9f, context:dagger.hilt.android.internal.managers.n@9c2b1ec
androidx.recyclerview.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition (RecyclerView.java:6544)
androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline (RecyclerView.java:6727)
androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:6688)
androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition (RecyclerView.java:6684)
androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next (LinearLayoutManager.java:2362)
androidx.recyclerview.widget.LinearLayoutManager.layoutChunk (LinearLayoutManager.java:1662)
androidx.recyclerview.widget.LinearLayoutManager.fill (LinearLayoutManager.java:1622)
androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren (LinearLayoutManager.java:687)
androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep1 (RecyclerView.java:4550)
androidx.recyclerview.widget.RecyclerView.dispatchLayout (RecyclerView.java:4305)
androidx.recyclerview.widget.RecyclerView.consumePendingUpdateOperations (RecyclerView.java:2065)
androidx.recyclerview.widget.RecyclerView$1.run (RecyclerView.java:438)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:1301)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:1309)
android.view.Choreographer.doCallbacks (Choreographer.java:923)
android.view.Choreographer.doFrame (Choreographer.java:847)
android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1283)
android.os.Handler.handleCallback (Handler.java:942)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loopOnce (Looper.java:226)
android.os.Looper.loop (Looper.java:313)
android.app.ActivityThread.main (ActivityThread.java:8757)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)
hi i got this error actually i have muilple viewtype in recycler and its loading ads two different types and one is item
also a grid view and linear view option
plz help how to resolve this crashe
ry...@google.com <ry...@google.com> #33
If you are hitting this, you are likely either updating the adapter on the background thread (all updates must occur on the main thread) or failing to correctly notify the adapter of dataset changes.
If you believe you aren't doing either of these things, please file a new bug with a sample app attached demonstrating the issue. We cannot really debug issues further without that.
Description
The exception itself is:
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{15796f40 position=-1 id=256279, oldPos=9, pLpos:6 no parent}
My workflow is as follows:
- When the activity is created an adapter is set
- When the search action mode is entered, setAdapter() is called with a new adapter that extends the previous one with an additional view type
- Typing filters the list of results
- Backing out replaces the adapter with the original one via setAdapter
There are specific letters that trigger it. For example, whenever I type "jo" and quickly delete both letters, it crashes. I think this is related with the first delete making the string "j" which returns more results than "jo" and the second delete making the string "" which returns only 1 result (of the special view type mentioned above). The second delete must happen before the animations of the first delete finish for the crash to happen.
Some details:
- I'm using the DefaultItemAnimator with setSupportsChangeAnimations(true)
- I only use notifyItemInserted(), notifyItemMoved(), notifyItemRemoved() and notifyItemChange() calls
Why I think it's a state problem:
- If I use notifyDataSetChanged(), there are no crashes
- If I disable animations, there are no crashes
- If I call getRecycledViewPool().clear() right after setAdapter(), there are no crashes
Library used: recyclerview-v7:21.0.3