title: getGeoPoint() method returns null when called. There is more than 1 document in the Firebase collection
body: <p>I'm following a tutorial on building a Chatroom app that includes <strong>User Location</strong> functionality with Google Maps API, however, I'm following it just to learn how to use the Google Maps API, I'm trying to build a Tracking App that can record traveled routes and access them by date, etc.</p>
  <p>There is a <code>UserLocation</code> object comprised of <strong>geolocation, timestamp, and a User object</strong>, and instances of it are stored in a Firestore Collection. The database works fine:</p>
  <p><a href="https://i.stack.imgur.com/E4wfM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E4wfM.png" alt="enter image description here" /></a></p>
  <p>However, after authentication I'm getting the following error:</p>
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.trackingapp, PID: 13386
      java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.firestore.GeoPoint com.example.trackingapp.models.UserLocation.getGeo_point()' on a null object reference
          at com.example.trackingapp.ui.MainActivity.setCameraView(MainActivity.java:109)
          at com.example.trackingapp.ui.MainActivity.onMapReady(MainActivity.java:410)
          at com.google.android.gms.maps.zzac.zza(Unknown Source)
          at com.google.android.gms.maps.internal.zzaq.dispatchTransaction(Unknown Source)
          at com.google.android.gms.internal.maps.zzb.onTransact(Unknown Source)
          at android.os.Binder.transact(Binder.java:499)
          at ds.b(:com.google.android.gms.dynamite_mapsdynamite@203615052@20.36.15 (040700-0):2)
          at com.google.maps.api.android.lib6.impl.bf.run(:com.google.android.gms.dynamite_mapsdynamite@203615052@20.36.15 (040700-0):2)
          at android.os.Handler.handleCallback(Handler.java:751)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:154)
          at android.app.ActivityThread.main(ActivityThread.java:6119)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  </code></pre>
  <p>I'm guessing I made a mistake trying to implement the original App's logic into mine.</p>
  <p>I'm almost certain the problem is how <code>mUserListEventListener</code> is used. This variable literally holds all of the logic to get the <strong>UserLocations</strong> into the <strong>ArrayList</strong>, but it is only called in the <strong>OnDestroy()</strong> method!!</p>
  <p>The tutorial's source code is written that way, there are no other usages for <code>mUserListEventListener</code>. I've tried to implement UserLocations logic elsewhere but I can't get it right.</p>
  <p>Here is the relevant MainActivity code. It is the only activity in my App (besides Login and Registration):</p>
  <pre><code>public class MainActivity extends AppCompatActivity implements OnMapReadyCallback {
  
      //    Variables Google Maps
      private boolean mLocationPermissionGranted = false;
      private MapView mMapView;
      private FusedLocationProviderClient mFusedLocationClient;
      private UserLocation mUserLocation;
      private ArrayList&lt;UserLocation&gt; mUserLocations = new ArrayList&lt;&gt;();
      private GoogleMap mGoogleMap;
      private LatLngBounds mMapBoundary;
      private UserLocation mUserPosition;
  
      //    Variables Firebase
      private FirebaseFirestore mDb;
      private ListenerRegistration mUserListEventListener;
      private Set&lt;String&gt; mUserIds = new HashSet&lt;&gt;();
  
  
      //    Otras Variables
      private RecyclerView rvUsers;
      private UserRecyclerAdapter adapter;
      private ArrayList&lt;User&gt; mUserList = new ArrayList&lt;&gt;();
      private static final String TAG = &quot;MainActivity&quot;;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          initGoogleMap(savedInstanceState);
  
          mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
  
          // DATA DE FIREBASE
          //
          mDb = FirebaseFirestore.getInstance();
          rvUsers = (RecyclerView) findViewById(R.id.user_list_recycler_view);
          getUsers();
          initUserRecyclerView();
          setUserPosition();
      }
  
      private void setCameraView(){
  
          double bottomBoundary = mUserPosition.getGeo_point().getLatitude() - .1;
          double leftBoundary = mUserPosition.getGeo_point().getLongitude() - .1;
          double topBoundary = mUserPosition.getGeo_point().getLatitude() + .1;
          double rightBoundary = mUserPosition.getGeo_point().getLongitude() + .1;
  
          mMapBoundary = new LatLngBounds(
                  new LatLng(bottomBoundary,leftBoundary),
                  new LatLng(topBoundary,rightBoundary)
          );
  
          mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngBounds(mMapBoundary,0));
      }
  
      private void setUserPosition(){
          for (UserLocation userLocation : mUserLocations){
              if (userLocation.getUser().getUser_id().equals(FirebaseAuth.getInstance().getUid())){
                  mUserPosition = userLocation;
              }
          }
      }
  
      private void getUserDetails(){
          if (mUserLocation == null){
              mUserLocation = new UserLocation();
  
              DocumentReference userRef = mDb.collection(&quot;Users&quot;)
                      .document(Objects.requireNonNull(FirebaseAuth.getInstance().getUid()));
  
              userRef.get().addOnCompleteListener(new OnCompleteListener&lt;DocumentSnapshot&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;DocumentSnapshot&gt; task) {
                      if (task.isSuccessful()){
                          Log.d(TAG, &quot;onComplete: successfully set the user details.&quot;);
  
                          User user = task.getResult().toObject(User.class);
                          mUserLocation.setUser(user);
                          ((UserClient)getApplicationContext()).setUser(user);
                          getLastKnownLocation();
                      }
                  }
              });
          }
          else {
              getLastKnownLocation();
          }
      }
  
      private void saveUserLocation(){
          if(mUserLocation != null){
              DocumentReference locationRef = mDb.
                      collection(&quot;User Locations&quot;)
                      .document(Objects.requireNonNull(FirebaseAuth.getInstance().getUid()));
  
              locationRef.set(mUserLocation).addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
                  @Override
                  public void onComplete(@NonNull Task&lt;Void&gt; task) {
                      if(task.isSuccessful()){
                          Log.d(TAG, &quot;saveUserLocation: \ninserted user location into database.&quot; +
                                  &quot;\n latitude: &quot; + mUserLocation.getGeo_point().getLatitude() +
                                  &quot;\n longitude: &quot; + mUserLocation.getGeo_point().getLongitude());
                      }
                  }
              });
          }
      }
  
      private void getLastKnownLocation() {
          Log.d(TAG, &quot;getLastKnownLocation: called&quot;);
  
          if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
              return;
          }
          mFusedLocationClient.getLastLocation().addOnCompleteListener(new OnCompleteListener&lt;Location&gt;() {
              @Override
              public void onComplete(@NonNull Task&lt;Location&gt; task) {
                  if (task.isSuccessful()){
                      Location location = task.getResult();
                      GeoPoint geoPoint = new GeoPoint(location.getLatitude(), location.getLongitude());
                      Log.d(TAG, &quot;onComplete: latitude: &quot; + geoPoint.getLatitude());
                      Log.d(TAG, &quot;onComplete: longitude&quot; + geoPoint.getLongitude());
  
                      mUserLocation.setGeo_point(geoPoint);
                      mUserLocation.setTimestamp(null);
                      saveUserLocation();
                  }
              }
          });
      }
  
  
  private void getUsers() {
  
          CollectionReference usersCollection = mDb
                  .collection(&quot;Users&quot;);
  
          mUserListEventListener = usersCollection.addSnapshotListener(new EventListener&lt;QuerySnapshot&gt;() {
              @Override
              public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
                  Log.d(TAG, &quot;onEvent: called.&quot;);
  
                  if (e != null) {
                      Log.e(TAG, &quot;onEvent: Listen failed.&quot;, e);
                      return;
                  }
  
                  if(queryDocumentSnapshots != null){
  
                      // Clear the list and add all the users again
                      mUserList.clear();
                      mUserList = new ArrayList&lt;&gt;();
  
                      for (QueryDocumentSnapshot doc : queryDocumentSnapshots) {
                          User user = doc.toObject(User.class);
                          mUserList.add(user);
                          getUserLocation(user);
                      }
  
                      Log.d(TAG, &quot;onEvent: user list size: &quot; + mUserList.size());
                  }
  
              }
          });
  
      }
  
      private void getUserLocation(User user){
          DocumentReference locationRef = mDb.collection(&quot;User Locations&quot;)
                  .document(user.getUser_id() );
  
          locationRef.get().addOnCompleteListener(new OnCompleteListener&lt;DocumentSnapshot&gt;() {
              @Override
              public void onComplete(@NonNull Task&lt;DocumentSnapshot&gt; task) {
                  if (task.isSuccessful()){
                      if(task.getResult().toObject(UserLocation.class) != null){
                          mUserLocations.add(task.getResult().toObject(UserLocation.class));
                      }
                  }
              }
          });
      }
  
  
      @Override
      protected void onResume() {
          super.onResume();
          if (checkMapServices()) {
              if (mLocationPermissionGranted) {
                  getUsers();
                  getUserDetails();
              } else {
                  getLocationPermission();
              }
          }
          mMapView.onResume();
      }
  
      @Override
      protected void onStart() {
          super.onStart();
          mMapView.onStart();
      }
  
      @Override
      protected void onStop() {
          super.onStop();
          mMapView.onStop();
      }
  
      @Override
      public void onMapReady(GoogleMap map) {
          map.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title(&quot;Marker&quot;));
          if (ActivityCompat.checkSelfPermission(this,
                  Manifest.permission.ACCESS_FINE_LOCATION)
                  != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(this,
                  Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
              return;
          }
          map.setMyLocationEnabled(true);
          mGoogleMap = map;
          setCameraView();
      }
  
      @Override
      protected void onPause() {
          mMapView.onPause();
          super.onPause();
      }
  
      @Override
      protected void onDestroy() {
          mMapView.onDestroy();
          super.onDestroy();
          if(mUserListEventListener != null){
              mUserListEventListener.remove();
          }
      }
  
      @Override
      public void onLowMemory() {
          super.onLowMemory();
          mMapView.onLowMemory();
      }
  
  }
  </code></pre>