title: Using variable from onComplete() method while working with Firestore database
body: <p>So I have a collection in Cloud Firestore and I need to store the informations from database in a list (coordPlaces). I did it like this, created these methods:</p>
  <pre><code>private void readData(FirestoreCallback firestoreCallback){
      db.collection(&quot;AddPlaces&quot;)
              .get()
              .addOnCompleteListener(new OnCompleteListener&lt;QuerySnapshot&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;QuerySnapshot&gt; task) {
                      if(task.isSuccessful()){
                          if(task.getResult() != null){
                              List&lt;ListPlacesModel&gt; list = task.getResult().toObjects(ListPlacesModel.class);
                              for(ListPlacesModel model : list)
                              {
                                  LatLng place = new LatLng(model.getPlaceLat(), model.getPlaceLng());
                                  coordPlaces.add(place);
                                  String name = model.getPlaceName();
                                  gMap.addMarker(new MarkerOptions().position(place).title(name));
                              }
                              firestoreCallback.onCallback(coordPlaces);
                          }
                      }
                      else {
                          Log.d(&quot;ERROR&quot;, String.valueOf(task.getException()));
                      }
                  }
              });
  }
  
  private interface FirestoreCallback{
          void onCallback(List&lt;LatLng&gt; myList);
      }
  </code></pre>
  <p>And then called the method like this:</p>
  <pre><code>db = FirebaseFirestore.getInstance();
          readData(new FirestoreCallback() {
              @Override
              public void onCallback(List&lt;LatLng&gt; myList) {  
          });
  </code></pre>
  <p>I've saw this solution in this <a href="https://www.youtube.com/watch?v=0ofkvm97i0s&amp;ab_channel=AlexMamo" rel="nofollow noreferrer">video</a>.</p>
  <p>But now I need to access this list in order to creathe a 2D array out of it, in this manner:</p>
  <pre><code>for(int i=0;i&lt;coordPlaces.size();i++)
  {
      for(int j=0;j&lt;coordPlaces.size();j++)
      {
        int distance = (int) SphericalUtil.computeDistanceBetween(coordPlaces.get(i), coordPlaces.get(i+1));
        graph[i][j] = distance;
      }
  }
  </code></pre>
  <p>Anywhere in the code where I put these 2 for loops, my app crashes. I can't find a solution of how to create this 2D array.
  Any ideas?</p>