Cannot Resolve Symbol "Place.Field"
Sebastian Wright
I am trying to migrate new Auto Complete Place Picker I have updated library from "com.google.android.gms:play-services" to new "com.google.android.libraries.places:places-compat:2.0.0" and implemented SupportPlaceAutocompleteFragment.
All works fine however the error I am getting is:
"Place.Field" Cannot resolve symbol 'Field'
Below is my code:
// Initialize the AutocompleteSupportFragment. SupportPlaceAutocompleteFragment supportPlaceAutocompleteFragment = (SupportPlaceAutocompleteFragment)getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
//List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);
// Specify the types of place data to return.
supportPlaceAutocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
// Set up a PlaceSelectionListener to handle the response.
supportPlaceAutocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() { @Override public void onPlaceSelected(Place place) { // TODO: Get info about the selected place. Toast.makeText(MapsActivity.this, "Place: " + place.getName() + ", " + place.getId(), Toast.LENGTH_LONG).show(); Log.i("", "Place: " + place.getName() + ", " + place.getId()); } @Override public void onError(Status status) { }
});
supportPlaceAutocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));Can you help me solve this error:
2
"Place.Field" Cannot resolve symbol 'Field'
2 Answers
Ensure that you import the correct Place class.
import com.google.android.libraries.places.api.model.Place;Hope this helps.
The SupportPlaceAutocompleteFragment class is deprecated. Please use the AutocompleteSupportFragment class instead. Refer to Google's migration guide and the Place Autocomplete's guide.
// Initialize the AutocompleteSupportFragment.
AutocompleteSupportFragment supportPlaceAutocompleteFragment = (AutocompleteSupportFragment) getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
//List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME);
// Specify the types of place data to return.
supportPlaceAutocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));
// Set up a PlaceSelectionListener to handle the response.
supportPlaceAutocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() { @Override public void onPlaceSelected(Place place) { Toast.makeText(MapsActivity.this, "Place: " + place.getName() + ", " + place.getId(), Toast.LENGTH_LONG).show(); Log.i("", "Place: " + place.getName() + ", " + place.getId()); } @Override public void onError(Status status) { }
});
supportPlaceAutocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME));Hope this helps!