我正在嘗試從 Firestore 獲取值,但每次都為 null。有人能告訴我我做錯了什么嗎?這是我的 Firestore 集合和檔案。

DocumentReference docRef = dbase.collection("newsImage").document("cqmpNF45IZsHDSx9hSuq");
colref.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull @NotNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
str = document.getString("imgNews");
tv.setText(str);
} else
Log.d("docv", "No such document");
} else
Log.d("docv", "get failed with ", task.getException());
}
});
uj5u.com熱心網友回復:
問題很可能來自以下代碼行:
String newsText= ipustr;
tv.setText(sectorText);
您嘗試分配不是來自資料庫的值的地方。所以很可能你應該做這樣的事情:
str = document.getString("imgNews");
tv.setText(str);
甚至是簡單的:
tv.setText(document.getString("imgNews"));
編輯:
提交的名稱不正確,請使用:
tv.setText(document.getString("imgnews"));
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/311259.html
標籤:爪哇 安卓 火力基地 谷歌云平台 谷歌云firestore
上一篇:根據角色隱藏元素
