【问题标题】:Getting an error while retrieving a number from a Firestore document从 Firestore 文档中检索数字时出错
【发布时间】:2020-04-07 00:00:09
【问题描述】:

我在文档的某个字段中存储了一个数字并想检索它,但出现以下错误: String resource ID #0x1

我正在使用this 方法来检索号码。存储在 Firestore 中的数字是 Long、Integer 还是 Double?我没有找到任何答案,我该如何解决这个错误,以便我可以检索该号码并在我的代码中使用它?

错误显示在Toast 行中。

非常感谢您的帮助!

这是我的代码:

    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();

                            }
                        }
                    }
                });
...

【问题讨论】:

  • 请将您的数据库结构添加为屏幕截图并指出发生该错误的行。
  • 我发现了问题,我在 Toast 消息中使用了整数

标签: android firebase google-cloud-firestore


【解决方案1】:

我发现了问题:

错误出现在 Toast 消息中,我没有将整数转换为字符串值。 这是正确的 Toast 消息:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-23
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 2020-12-22
    • 1970-01-01
    相关资源
    最近更新 更多