question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid view holder adapter position

See original GitHub issue

Hi, the library is really great due to its modular design. It really does help a lot.

Unfortunately I have encountered an issue. I will first show some code, but I do not have a small, executable example at the moment, I might add it later.

My code uses the OneAdapter as follows:

Within the fragment:

recyclerView = view.findViewById(R.id.ingredients_list);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
oneAdapter = new OneAdapter(recyclerView);
oneAdapter.attachEmptinessModule(new PantryEmptinessModule());
oneAdapter.attachPagingModule(new PantryPagingModule());
oneAdapter.attachItemModule(new PantryItemModule());
prepopulateAdapter();

Within prepopulateAdapter (on main thread):

oneAdapter.add(recipes); //recipes is an ArrayList

Within PantryPagingModule:

@Override
public PagingModuleConfig provideModuleConfig() {
    return new PagingModuleConfig() {
        @Override
        public int withVisibleThreshold() {
            return 3;
        }
        @Override
        public int withLayoutResource() {
            return R.layout.load_more_item;
        }
    };
}

@Override
public void onLoadMore(int i) {
     //Recipes are obtained in the background...
     //on main thread
      oneAdapter.add(recipes); //recipes is an ArrayList
}

The item looks as follows:

@PrimaryKey
    public int id;

    @ColumnInfo(name = "name")
    public String name;

    @ColumnInfo(name = "amount")
    public int amount;

    @Override
    public boolean areContentTheSame(@NotNull Object o) {
        if (!(o instanceof Recipe)) {
            return false;
        }
        Ingredient other = (Recipe) o;
        boolean names = this.name.equals(other.name);
        boolean amount = this.amount == other.amount;
        return names && amount;
    }

    @Override
    public long getUniqueIdentifier() {
        return id;
    }

And the error message that sometimes comes when scrolling is:

ava.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder

Now, I have no idea where this error might come from. Maybe we can find a solution to this and fix it. If any more information is needed, I’ll be happy to help. Thanks in advance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:24 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
palVikas9commented, Feb 25, 2020

@meruiden Please try recyclerView.setItemAnimator(null);

I was also having the same problem and this line solved the issue. I am not sure why this is happening but this helped me to get the problem solved. It is most probably occurring due the Diffable implementation of the model class.

2reactions
Keickdcommented, May 4, 2021

@meruiden Please try recyclerView.setItemAnimator(null);

I was also having the same problem and this line solved the issue. I am not sure why this is happening but this helped me to get the problem solved. It is most probably occurring due the Diffable implementation of the model class.

You saved my life, i spent several days looking for a solution and this line made my day man 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

RecyclerView and java.lang.IndexOutOfBoundsException ...
RecyclerView and java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder in Samsung devices.
Read more >
Inconsistency detected. Invalid view holder adapter ... - GitHub
I followed a basic usage tutorial and I got a exception: Process: com.example, PID: 13642 java.lang.IndexOutOfBoundsException: Inconsistency detected.
Read more >
RecyclerView doesn't properly clear state when setAdapter ...
I'm facing an issue with RecyclerView that seems to be related with it not clearing the state properly when setAdapter() is called. The...
Read more >
Solution for RecyclerView — IndexOutOfBoundsException
Invalid Item ## Item Position, etc. Let's see a few ways to fix this. Understand why this happens. When the user scrolls your...
Read more >
RecyclerView.Adapter - Android Developers
Returns the position of the given ViewHolder in the given Adapter . If the given Adapter is not part of this Adapter ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found