Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 执行异步操作时,RecyclerView不显示数据_Android_Android Recyclerview_Android Asynctask_Google Cloud Firestore_Android Livedata - Fatal编程技术网

Android 执行异步操作时,RecyclerView不显示数据

Android 执行异步操作时,RecyclerView不显示数据,android,android-recyclerview,android-asynctask,google-cloud-firestore,android-livedata,Android,Android Recyclerview,Android Asynctask,Google Cloud Firestore,Android Livedata,在notifyChanges()中,如果没有任何异步操作,my recyclerview将显示数据。但是当我执行异步操作时,RecyclerView是空的。原因可能是什么?提前谢谢 profileList = changes; 不要从主线程以外的任何其他线程调用notifyDataSetChanged()。只需从doInBackground()中删除对invalidate()的调用,并将其添加到onPostExecute() 当对ArrayList进行迭代时,不应修改它。不要在ArrayLis

在notifyChanges()中,如果没有任何异步操作,my recyclerview将显示数据。但是当我执行异步操作时,RecyclerView是空的。原因可能是什么?提前谢谢

profileList = changes;

不要从主线程以外的任何其他线程调用
notifyDataSetChanged()
。只需从
doInBackground()
中删除对
invalidate()
的调用,并将其添加到
onPostExecute()

当对ArrayList进行迭代时,不应修改它。不要在ArrayList上使用
remove()
方法,而要在迭代器上使用
remove()
方法

@Override
protected void onPostExecute(Void aVoid) {
    Log.w("PROCESS EXECUTED", String.valueOf(profileList.size()));
    invalidate();
}

不要从主线程以外的任何其他线程调用
notifyDataSetChanged()
。只需从
doInBackground()
中删除对
invalidate()
的调用,并将其添加到
onPostExecute()

当对ArrayList进行迭代时,不应修改它。不要在ArrayList上使用
remove()
方法,而要在迭代器上使用
remove()
方法

@Override
protected void onPostExecute(Void aVoid) {
    Log.w("PROCESS EXECUTED", String.valueOf(profileList.size()));
    invalidate();
}

我相信
ConcurrentModificationException
的问题就在这里

@Override
protected Void doInBackground(List<ProfileSearchResult>... lists) {
    synchronized (profileList) {
        Iterator<ProfileSearchResult> iter = profileList.iterator();
        while (iter.hasNext()) {
            ProfileSearchResult result = iter.next();

            if(false == profileListNew.contains(result)){
                iter.remove();
            }
        }
        iter = profileListNew.iterator();
        while (iter.hasNext()) {
            ProfileSearchResult result = iter.next();

            if(false == profileList.contains(result)){
                profileList.add(result);
            }
        }
        return null;
    }
}
Iterator iter=profileList.Iterator();
while(iter.hasNext()){
ProfileSearchResult=iter.next();
if(false==profileListNew.contains(结果)){

profileList.remove(result);//我相信
ConcurrentModificationException
的问题就在这里

@Override
protected Void doInBackground(List<ProfileSearchResult>... lists) {
    synchronized (profileList) {
        Iterator<ProfileSearchResult> iter = profileList.iterator();
        while (iter.hasNext()) {
            ProfileSearchResult result = iter.next();

            if(false == profileListNew.contains(result)){
                iter.remove();
            }
        }
        iter = profileListNew.iterator();
        while (iter.hasNext()) {
            ProfileSearchResult result = iter.next();

            if(false == profileList.contains(result)){
                profileList.add(result);
            }
        }
        return null;
    }
}
Iterator iter=profileList.Iterator();
while(iter.hasNext()){
ProfileSearchResult=iter.next();
if(false==profileListNew.contains(结果)){

profileList.remove(结果);//原因:java.util.ConcurrentModificationException我也收到了这个错误!谢谢你的帮助!@SachinTitus你能发布完整的堆栈跟踪吗?当然……一秒钟原因:java.util.ConcurrentModificationException我也收到了这个错误!谢谢你的帮助!@SachinTitus你能发布完整的堆栈跟踪吗?当然……一秒钟
@Override
protected Void doInBackground(List<ProfileSearchResult>... lists) {
    synchronized (profileList) {
        Iterator<ProfileSearchResult> iter = profileList.iterator();
        while (iter.hasNext()) {
            ProfileSearchResult result = iter.next();

            if(false == profileListNew.contains(result)){
                iter.remove();
            }
        }
        iter = profileListNew.iterator();
        while (iter.hasNext()) {
            ProfileSearchResult result = iter.next();

            if(false == profileList.contains(result)){
                profileList.add(result);
            }
        }
        return null;
    }
}
Iterator<ProfileSearchResult> iter = profileList.iterator();
        while (iter.hasNext()) {
            ProfileSearchResult result = iter.next();

            if(false == profileListNew.contains(result)){
                profileList.remove(result); // <------- here <-------
            }
        }