I am trying to retrieve the value of year from a collection on cloud firestore, I will use this year value to retrieve data from the firestore storage. The code I am using for doing this is
DocumentReference documentReference = fStore.collection("Users").document(userId);
documentReference.addSnapshotListener(this, new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(@Nullable DocumentSnapshot value, @Nullable FirebaseFirestoreException error) {
if (error != null){
if (progressDialog.isShowing())
progressDialog.dismiss();
Log.e("Firestore error",error.getMessage());
return;
}
assert value != null;
String gyear = value.getString("Year");
setYear(gyear);
}
});
storageReference = FirebaseStorage.getInstance().getReference("AcademicCalendar/"+getYear()+"/AC.jpg");
here the setYear and getYear are setter and getter for the year variable of type string. I want to store the value of year from firestore to this string. But when I do so I am getting the value as null. Below I have printed the storageReference, as you can see the value is null.
I/System.out: StorageRefgs://dsu-app-cm.appspot.com/AcademicCalendar/null/AC.jpg
could your please help me find a way to store the year in a string variable so I can use it to retrieve data from firebase storage?