When i update my list in recyclerview while scrolling its crash

Viewed 218

When i update my list in recyclerview while scrolling, my app crashes with the following stacktrace:

Adapter class

public class NotesAdapter extends RecyclerView.Adapter<NotesAdapter.MyViewHolder> {
private Context context;
public static List<Note> notesList; 

public class MyViewHolder extends RecyclerView.ViewHolder {
        public TextView note;
 

        public MyViewHolder(View view) {
            super(view);
            note = view.findViewById(R.id.note);
            
        }
    }
public NotesAdapter(Context context, List<Note> notesList) {
        this.context = context;
        this.notesList = notesList; 
    }

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.note_list_row, parent, false);
    

     return new MyViewHolder(itemView);
}


@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {

final Note note = notesList.get(position);
            holder.note.setText(note.getNote());
}

@Override
public int getItemCount() {
    return notesList.size() ;
}
}

When I Scroll recyclerview while updating its crash that's all code I have now please help me out with this crash... i update my list whenever notification came on my phone so the whole list is updated and if you are scrolling and list get updated my app crash

java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{86b8f8b position=1 id=-1, oldPos=-1, pLpos:-1 no parent} androidx.recyclerview.widget.RecyclerView{d8043c1 VFED..... ........ 0,0-1080,1369 #7f0a00ff app:id/recyclerView}, adapter:com.uzeegar.unseen.nolastseen.hiddenchat.Adapter.NotesAdapter@c87d766, layout:com.uzeegar.unseen.nolastseen.hiddenchat.Utilz.WrapContentLinearLayoutManager@85bfaa7, context:androidx.multidex.MultiDexApplication@5fed17c
    at androidx.recyclerview.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:5715)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5898)
    at androidx.recyclerview.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:286)
    at androidx.recyclerview.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:343)
    at androidx.recyclerview.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:359)
    at androidx.recyclerview.widget.GapWorker.prefetch(GapWorker.java:366)
    at androidx.recyclerview.widget.GapWorker.run(GapWorker.java:397)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7050)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
1 Answers

I Sort out my Problem by adding the frame layout which I used for Native Ad in the same layout and make the visibility Gone ... and show the AD Visible only on that position which I want to show the Ad...

Related