[英]ArrayList IndexOfBound exceptions when to get data from firestore database, why?
[英]How to get data into an Arraylist in a collection in the Firestore Database?
我正在使用雲 Firestore 數據庫,我有一個名為 Jobpost1 的集合。 我想從這個集合中獲取數據並存儲在數組列表中。
我的Java代碼
List<Jobpost> mList = new ArrayList<>(); //this is my arraylist
private CollectionReference collectionReference=db.collection("Job Post1");
@Override
public void onStart() {
super.onStart();
collectionReference.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (!queryDocumentSnapshots.isEmpty()){
for (QueryDocumentSnapshot journals: queryDocumentSnapshots){
}
}else {
noJournalEntry.setVisibility(View.VISIBLE);
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
}
您可以通過這種方式填充列表
List<Jobpost> mList = new ArrayList<>(); //this is my arraylist
private CollectionReference collectionReference=db.collection("Job Post1");
@Override
public void onStart() {
super.onStart();
collectionReference.get()
.addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
@Override
public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
if (!queryDocumentSnapshots.isEmpty()){
for (QueryDocumentSnapshot journals: queryDocumentSnapshots){
JobPost jobPost= journals.toObject(JobPost.class);
mList.add(jobPost);
}
}else {
noJournalEntry.setVisibility(View.VISIBLE);
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.