[英]Getting an error while retrieving a number from a Firestore document
我在文檔的字段中存儲了一個數字並想檢索它,但出現以下錯誤: String resource ID #0x1
我正在使用這種方法來檢索號碼。 存儲在 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 消息中,我沒有將整數轉換為字符串值。 這是正確的 Toast 消息:
Toast.makeText(PlayInterimResultMainActivity.this, round.toString(), Toast.LENGTH_SHORT).show();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.