Android RecyclerView notify不';t工作正常

Android RecyclerView notify不';t工作正常,android,android-recyclerview,Android,Android Recyclerview,我正在使用RecyclerView制作应用程序,有时我会更改项目并立即通知notifyDataSetChanged()或notifyItemRemoved(position),但我的应用程序有时会崩溃,但有时也不会例外: java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetCh

我正在使用RecyclerView制作应用程序,有时我会更改项目并立即通知
notifyDataSetChanged()
notifyItemRemoved(position)
,但我的应用程序有时会崩溃,但有时也不会例外:

java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 55, found: 56 
代码#1: 我的代码是:

imageList.add(file);
listener.onChange();
听众:

@Override
public void onChange() {
   photoAdapter.notifyDataSetChanged();
 }
代码#2: 与代码的另一部分相同:

files.remove(file);
notifyItemRemoved(poss);
我不知道哪里出错了。你知道什么是可能的错误吗? 如果有必要,我可以发布一些附加代码

提前谢谢

编辑:代码#2中的错误代码:


这是一样的,第一部分代码是在一个单独的线程上运行的吗?我想问题出在你的适配器上。你能给我们看一下
适配器的代码吗?有很多行代码与这个问题没有任何联系,你感兴趣的代码是什么?
  for (File f : files) {
        if (f.getAbsolutePath().equals(file.getAbsolutePath())) {
            final int poss = files.indexOf(file);
            files.remove(file);
            notifyItemRemoved(poss);
            break;
        }
    }