简体   繁体   English

从 Firestore 文档中检索数字时出错

[英]Getting an error while retrieving a number from a Firestore document

I stored a number in a field of a document and want to retrieve it but I get the following error: String resource ID #0x1我在文档的字段中存储了一个数字并想检索它,但出现以下错误: String resource ID #0x1

I am using this method to retrieve the number.我正在使用这种方法来检索号码。 Is the number stored in Firestore as Long, Integer or Double?存储在 Firestore 中的数字是 Long、Integer 还是 Double? I didn't find any answer to that, and how can I resolve this error so I can retrieve the number and use it in my code?我没有找到任何答案,我该如何解决这个错误,以便我可以检索号码并在我的代码中使用它?

The error is displayed in the Toast line.错误显示在Toast行中。

Your help is very much appreciated!非常感激您的帮忙!

Here is my code:这是我的代码:

    Integer round;

    private FirebaseFirestore db = FirebaseFirestore.getInstance();
    private CollectionReference roundRef = db.collection("Games");

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play_interim_result);

       ...

        roundRef.document(gameId).collection("Round").document("Round").get()
                .addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                        if (task.isSuccessful()){
                            DocumentSnapshot document = task.getResult();
                            if (document != null){

                                round = document.getLong("round").intValue();

                                Toast.makeText(PlayInterimResultMainActivity.this, round, Toast.LENGTH_SHORT).show();

                            }
                        }
                    }
                });
...

I found the problem:我发现了问题:

The error was in the Toast message, where I didn't transformed the integer into a String value.错误出现在 Toast 消息中,我没有将整数转换为字符串值。 Here is the right Toast message:这是正确的 Toast 消息:

Toast.makeText(PlayInterimResultMainActivity.this, round.toString(), Toast.LENGTH_SHORT).show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Firestore 获取文档时的错误处理 - Error handling when getting document from Firestore 在 Flutter 中从 Firestore 检索和投射单个文档 - Retrieving and casting single document from Firestore in Flutter 从 Cloud Firestore 数据库检索数据时出错 - Error retrieving data from Cloud Firestore database 创建 Firestore 文档时获取权限错误 - Getting permission error when creating a Firestore document 从一个 firestore 文档中检索数据以查询另一个 - Retrieving data from one firestore document to query another Firestore 错误:文档必须具有偶数个路径元素 - Firestore error: A document must have an even number of path elements 试图从 firestore 获取数据但出现此错误 - trying to get data from firestore but getting this ERROR 使用 firestore.FieldValue.increment(1) 时如何解决错误“参数“dataOrField”的值不是有效的 Firestore 文档”? - How to resolve error "Value for argument "dataOrField" is not a valid Firestore document" while using firestore.FieldValue.increment(1)? 我在尝试将数据从云 Firestore 带到我的 flutter 应用程序时遇到此错误 - I am getting this error while am trying to bring data from cloud firestore to my flutter app 从firestore(firebase)获取数据时出现错误。 我正在使用本机反应 - I am getting an error while fetching data from firestore(firebase). I am using react native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM