【发布时间】:2019-02-24 20:29:18
【问题描述】:
我在我的项目中使用 AutocompleteSupportFragment
AutocompleteSupportFragment places places = (AutocompleteSupportFragment)
getSupportFragmentManager().findFragmentById(R.id.place_autocompleteFragment);
places.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
places.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(@NonNull Place place) {
try {
if ( location_switch.isChecked() ) {
if ( place.getName() != null ) {
destination = place.getName().toString();
destination = destination.replace(" ", "+");
if ( Constants.IS_LOGG_ENABLE ) {
Log.d(Constants.TAG, "Destination Location = " + destination);
Log.d(Constants.TAG, "Place: " + place.getName() + ", Place ID: " + place.getId());
Log.d(Constants.TAG, "Address = " + place.getAddress());
}
getDirection();
} else {
Toast.makeText(DriverMainActivity.this, "Error occurred, please try again.", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(DriverMainActivity.this, "Please change your status to ONLINE", Toast.LENGTH_SHORT).show();
}
}catch (Exception ex){
if(Constants.IS_LOGG_ENABLE){
ex.printStackTrace();
}
}
}
完美地告诉我地名和身份证,但我需要那个选定地点的地址
Log.d(Constants.TAG, "Place: " + place.getName() + ", Place ID: " + place.getId());
像这样,但我在这一行得到 java.lang.NullPointerException
Log.d(Constants.TAG, "Address = " + place.getAddress());
【问题讨论】:
-
能否请您发布堆栈跟踪?
标签: android google-maps android-fragments