我创建了FiltersQueryAdapter作为mainAdapter,它已传递给setupPhotoFilters方法,其中mainadapter被辅助到setAdapter。有可能因为parseGeoPointfromLocation不在FiltersQueryApdapter的范围内,它返回的null是我在这种情况下做的云吗?
/*
* Helper method to get the Parse GEO point representation of a location
*/
public ParseGeoPoint geoPointFromLocation(Location loc) {
return new ParseGeoPoint(loc.getLatitude(), loc.getLongitude());
}
FiltersQueryAdapter mainAdapter = new FiltersQueryAdapter(this, PhotoFiltersAdapter.class
, new ParseRecyclerQueryAdapter.QueryFactory() {
public ParseQuery create() {
Location myLoc = (currentLocation == null) ? lastLocation : currentLocation;
ParseQuery query = ParseQuery.getQuery("PlaceFilters");
//query.include("user");
query.orderByAscending("GeoArea");
query.whereWithinKilometers("GeoArea", geoPointFromLocation(myLoc), radius);
query.setLimit(6);
return query;
}
});
private void setupPhotoFilters() {
rvFilters.setHasFixedSize(true);
rvFilters.setAdapter(mainAdapter);
rvFilters.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
}
答案 0 :(得分:1)
您假设此行始终返回非空值:
currentBestLocation = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
javadoc表示它可以为null,因此您应该在使用它之前检查它。您通过getCurrentLocation()传播该值,因此请在那里进行检查。