当我在recyclerview中更新我的列表,同时滚动它的崩溃

jgovgodb  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(363)

当我在滚动时在recyclerview中更新列表时,我的应用程序会崩溃,并出现以下堆栈跟踪:
适配器类

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() ;
}
}

当我滚动recyclerview,同时更新其崩溃,这是所有的代码,我现在请帮助我解决这个崩溃。。。我更新我的名单,每当通知到我的手机,所以整个名单是更新的,如果你是滚动和名单得到更新我的应用程序崩溃

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)
iqih9akk

iqih9akk1#

我解决了我的问题,增加了框架布局,我用的本地广告在同一布局,使可见性消失。。。只在我想显示广告的位置显示广告。。。

相关问题