我正在尝试使用来自 Google 网站的一些代码来实现 google 自动完成小部件。我在这一行有一个错误:
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener()
错误是: 类“派生自 PlaceSelectedListener 的匿名类”必须声明为抽象类或在“PlaceSelectionListener”中实现抽象方法“onError(Status)”
还有这个错误:
@Override
public void onError(AsyncTask.Status status
错误是:方法没有覆盖其父类(super class)中的方法
我可以深入了解如何解决这些错误吗?
public class Preferences extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preferences);
final TextView text = (TextView)findViewById(R.id.textView3);
final String TAG = Preferences.class.getSimpleName();
PlaceAutocompleteFragment autocompleteFragment = (PlaceAutocompleteFragment)
getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
Log.i(TAG, "Place: " + place.getName());
String placeDetailsStr = place.getName() + "\n"
+ place.getId() + "\n"
+ place.getLatLng().toString() + "\n"
+ place.getAddress() + "\n"
+ place.getAttributions();
text.setText(placeDetailsStr);
}
@Override
public void onError(AsyncTask.Status status) {
// TODO: Handle the error.
Log.i(TAG, "An error occurred: " + status);
}
});
}
最佳答案
我找到了解决方案: 我改变了:
@Override
public void onError(AsyncTask.Status status) {
// TODO: Handle the error.
Log.i(TAG, "An error occurred: " + status);
}
到:
@Override
public void onError(Status status) {
Log.i(TAG, "An error occurred: " + status);
}
关于java - 类 'Anonymous class derived from PlaceSelectedListener' 必须声明为抽象或实现抽象方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35560018/