首页 > 解决方案 > 无法解析 Firestore 中的方法增量(错误:找不到符号方法增量(int))

问题描述

我无法让这段代码工作:


import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.model.value.FieldValue;

private FirebaseFirestore db;

public void onCreate(){
...
db = FirebaseFirestore.getInstance();
...
}

private void increment() {
        DocumentReference washingtonRef = db.collection("cities").document("DC");

        // Atomically increment the population of the city by 50.
        washingtonRef.update("population", FieldValue.increment(50));
    }

我尝试同时使用:

com.google.firebase.firestore

com.google.firebase.firestore.model.value

但它仍然不起作用

当我尝试构建它时,出现错误:

找不到符号方法增量(int)

标签: androidgoogle-cloud-firestore

解决方案


正确的类是com.google.firebase.firestore.FieldValue.

如果使用该路径未向您显示increment方法,则您很可能使用的 SDK 版本尚不包含该方法。检查您的 gradle 文件,然后升级到最新版本。


推荐阅读