首页 > 解决方案 > Firebase firestore database returns null, the Query Snapshot value is empty but I have data stored on firestore, why is this returning null?

问题描述

here is the code I am using:

database.collection("final")
    .addSnapshotListener(new EventListener<QuerySnapshot>() {
        @Override
        public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) {
            assert value != null;
            Log.d("TAG", "onEvent: "+ value.isEmpty());
            models.clear();
      
            for (DocumentSnapshot snapshot : value.getDocuments()){
                FirebaseModel model = snapshot.toObject(FirebaseModel.class);
                assert model != null;
                models.add(model);
            }
            adapter.notifyDataSetChanged();
        }
    });
public class FirebaseModel {

    private String image;
    private String title;
    private String detail;

    public FirebaseModel() {
    }

    public FirebaseModel(String image, String title, String detail) {
        this.image = image;
        this.title = title;
        this.detail = detail;
    }

    public String getImage() {
        return image;
    }

    public void setImage(String image) {
        this.image = image;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }
}

this is image of firestore database

The value.getDocuments(); returns null but I have saved data on firestore database.

Log.d(TAG, "onEvent: "+ value.isEmpty()); 

this log returns onEvent: True which means it returns null not the data stored on firebase firestore

标签: androidfirebasegoogle-cloud-firestore

解决方案


推荐阅读