java - 从 Cloud FireStore Android 读取数据
问题描述
此脚本是否错误,因为我收到的数据是null
我在 Cloud Firestore 上添加数据时收到的。我不使用RecyclerView
,因为我只需要一个数据。
这是脚本:
private void getCustomer(){
firestoreDB.collection("customer")
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
customers = new ArrayList<>();
for (DocumentSnapshot doc : task.getResult()) {
Customer customer = doc.toObject(Customer.class);
customer.setId_customer(doc.getId());
customers.add(customer);
}
} else {
// Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
firestoreListener = firestoreDB.collection("customer")
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(QuerySnapshot documentSnapshots, FirebaseFirestoreException e) {
if (e != null) {
// Log.e(TAG, "Listen failed!", e);
return;
}
customers = new ArrayList<>();
for (DocumentSnapshot doc : documentSnapshots) {
Customer customer = doc.toObject(Customer.class);
customer.setId_customer(doc.getId());
customers.add(customer);
}
}
});
id_customer = customers.get(0).getId_customer();
}
这是我的火库:
解决方案
推荐阅读
- qt - 关于 Qt Test 的四个特殊插槽使用的真实世界代码示例
- html - HTML 文件自动添加了不需要的注释
- java - 如何使用 Java 11 获取 CPU 利用率
- sql - 如何选择具有 column1= 的行
column2 是其中的最大值吗? - jenkins-pipeline - 从 git 导入类 - 无法解析类
- sql - 当另一行没有值时需要计算一行的值 - SQL
- python - 将python文件和txt文件打包成exe
- javascript - 尝试在 Android 手机上使用生物识别身份验证时出现错误代码 605
- javascript - 关于新 Promise 中抛出错误的问题
- x86-64 - 处理中断时是否禁用中断?