我正在 YouTube 上关注本教程,我也在做同样的事情,也许我放错了地方或忘记了某个我还无法识别的代码,我对此还是个新手,
所以我得到的错误是。
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.www.riderapp.model.Rider.getName()' on a null object reference
at com.example.www.riderapp.Home$5$1.onDataChange(Home.java:391)
这是我的 Home.java 文件方法
private void loadAllAvailableDrivers() {
//Load all drivers within 3km distance
DatabaseReference driverLocation = FirebaseDatabase.getInstance().getReference(Common.driver_tbl);
GeoFire gf = new GeoFire(driverLocation);
GeoQuery geoQuery = gf.queryAtLocation(new GeoLocation(mLastLocation.getLatitude(),mLastLocation.getLongitude()),distance);
geoQuery.removeAllListeners();
geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
@Override
public void onKeyEntered(String key, final GeoLocation location) {
// Use key to get email from table users
//Table Users is table when driver register account and update information
FirebaseDatabase.getInstance().getReference(Common.user_driver_tbl)
.child(key)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
//Because Rider and User model is same properties
Rider rider = dataSnapshot.getValue(Rider.class);
//Add drivers to map
mMap.addMarker(new MarkerOptions()
.position(new LatLng(location.latitude, location.longitude))
.flat(true)
ERRR -----> .title(rider.getName())
.snippet("Phone : "+rider.getPhone())
.icon(BitmapDescriptorFactory.fromResource(R.drawable.car)));
}
相关分类