Class 'Anonymous class derived from PlaceSelectionListener' 必须声明为抽象或实现抽象方法

Class 'Anonymous class derived from PlaceSelectionListener' must either be declared abstract or implement abstract method

我想使用 Place Autocomplete 所以我阅读了 google 文档 我使用了 'Embed an AutocompleteSupportFragment' 选项 但我输入的完全一样,由google写的但是有这样的错误

  1. Class 'Anonymous class derived from PlaceSelectionListener' 必须声明为抽象方法或在 'PlaceSelectionListener'
  2. 中实现抽象方法 'onPlaceSelected(Place)'
  3. 方法未覆盖其超类中的方法

我确实重写了方法 'onPlaceSelected' 但是当我输入代码时,代码变成了灰色和在下面的 PlaceSelectionListener 中创建的红线..

我不知道为什么所以请帮助...

代码在这里

public class FinalTest extends FragmentActivity {
    private static int AUTOCOMPLETE_REQUEST_CODE = 1;
    private static final String TAG = "FinalTest";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_final_test);

        Places.initialize(getApplicationContext(), "my_api_key");
        PlacesClient placesClient = Places.createClient(this);

        // Initialize the AutocompleteSupportFragment.
        AutocompleteSupportFragment autocompleteFragment = (AutocompleteSupportFragment)
                getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);

        // Specify the types of place data to return.
        autocompleteFragment.setTypeFilter(TypeFilter.ADDRESS);

        autocompleteFragment.setLocationBias(RectangularBounds.newInstance(
                new LatLng(-33.880490, 151.184363),
                new LatLng(-33.858754, 151.229596)));
        autocompleteFragment.setCountries("IN");
        autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID,Place.Field.NAME));

        // Set up a PlaceSelectionListener to handle the response.
        autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
            @Override
            public void onPlaceSelected(Place place) {
                // TODO: Get info about the selected place.
                Log.i(TAG, "Place: " + place.getName() + ", " + place.getId());
            }

            @Override
            public void onError(Status status) {
                // TODO: Handle the error.
                Log.i(TAG, "An error occurred: " + status);
            }
        });
    }
}

你没有显示你的导入,但我猜你有这个导入:

import com.google.android.gms.location.places.ui.PlaceSelectionListener;

改为:

import com.google.android.libraries.places.widget.listener.PlaceSelectionListener;