数组操作有时会抛出“上一操作后操作无效" [英] Array operations sometimes throws 'Operation is invalid after previous operation'

查看:68
本文介绍了数组操作有时会抛出“上一操作后操作无效"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的一个解析子类中,我有一个像这样的方法:

In one of my parse subclasses I have a method like this:

public void updateCheckpoint(String checkpoint, boolean checked) {
    if (checked) {
        addUnique(checkedCheckpoints, checkpoint);
    } else {
        removeAll(checkedCheckpoints, Arrays.asList(checkpoint));
    }
}

此更新之后立即固定到本地数据存储.

This update is immediately followed by a pinning to the local datastore.

即使添加一个ProgressDialog来确保两次更新之间的固定都已完成,有时也会抛出Operation is invalid after previous operation.

Even when adding a ProgressDialog to ensure that the pinning has completed between updates, then sometimes the Operation is invalid after previous operation is thrown.

是否有更健壮的数组操作方式?

Is there a more robust way of doing array operations?

推荐答案

在解析数组下的文档它说

请注意,当前不可能在同一保存中原子地添加和删除数组中的项目.您将不得不在每种不同类型的数组操作之间调用save."

"Note that it is not currently possible to atomically add and remove items from an array in the same save. You will have to call save in between every different kind of array operation."

当您同时添加和删除解析对象时,它将引发错误上一次操作后操作无效".为避免此错误,请先将新值添加到数组,保存对象,删除旧值,然后再次保存.

When you both add and remove from your parse object, it will throw the error "Operation is invalid after previous operation". To avoid this error first add the new values to the array, save the object, remove the old values, then save again.

这篇关于数组操作有时会抛出“上一操作后操作无效"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆