title: How to retrieve any value from Firestore collections and store it in a variable?
body: <p>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</p>
  <pre><code>        DocumentReference documentReference = fStore.collection(&quot;Users&quot;).document(userId);
          documentReference.addSnapshotListener(this, new EventListener&lt;DocumentSnapshot&gt;() {
              @Override
              public void onEvent(@Nullable DocumentSnapshot value, @Nullable FirebaseFirestoreException error) {
                  if (error != null){
  
                      if (progressDialog.isShowing())
                          progressDialog.dismiss();
                      Log.e(&quot;Firestore error&quot;,error.getMessage());
                      return;
                  }
                  assert value != null;
                  String gyear = value.getString(&quot;Year&quot;);
                  setYear(gyear);
              }
          });
         storageReference = FirebaseStorage.getInstance().getReference(&quot;AcademicCalendar/&quot;+getYear()+&quot;/AC.jpg&quot;);
  
  </code></pre>
  <p>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.</p>
  <pre><code>I/System.out: StorageRefgs://dsu-app-cm.appspot.com/AcademicCalendar/null/AC.jpg
  </code></pre>
  <p>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?</p>