Расположение ошибки NullPointerException в проекте Android-GeoFire - PullRequest
0 голосов
/ 10 мая 2018

Просто привыкаю к ​​Java и Android, и у меня появляется вышеуказанная ошибка.

Это срабатывает, когда я нажимаю кнопку в приложении, которая будет искать пользовательский тип «респондент». Приложение вылетает, и я получаю эту ошибку:

 java.lang.NullPointerException: Attempt to invoke virtual method 'double android.location.Location.getLatitude()' on a null object reference
                      at com.jamesboyle.firsthelp.PatientMapActivity$2.onClick(PatientMapActivity.java:83)

Я не уверен, какой объект сейчас является нулевым из этого

mRequest.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String userID = FirebaseAuth.getInstance().getCurrentUser().getUid();

                    DatabaseReference ref = FirebaseDatabase.getInstance().getReference("patientRequest");
                    GeoFire geoFire = new GeoFire(ref);
                    geoFire.setLocation(userID, new GeoLocation(mLastLocation.getLatitude(), mLastLocation.getLongitude()));

                    pickupLocation = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());
                    mMap.addMarker(new MarkerOptions().position(pickupLocation).title("Respond Now"));

                    mRequest.setText("Locating Responder...");

                    getClosestResponder();
                }
            });
        }
        private int radius =1;
        private Boolean responderFound = false;
        private String responderFoundID;
        private void getClosestResponder(){
            DatabaseReference responderLocation = FirebaseDatabase.getInstance().getReference().child("respondersAvailable");

            GeoFire geoFire = new GeoFire(responderLocation);

            GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(pickupLocation.latitude, pickupLocation.longitude), radius);
            geoQuery.removeAllListeners();

            geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
                @Override
                public void onKeyEntered(String key, GeoLocation location) {
                    if (!responderFound) {
                        responderFound = true;
                        responderFoundID = key;
                    }
                }
...