class'从PlaceSelectedListener派生的匿名类'必须声明为抽象或实现抽象方法

时间:2016-02-22 17:27:31

标签: java android

我尝试使用Google网站上的一些代码来实施Google自动完成小部件。我在这一行上有一个错误:

autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener()

错误是: class'从PlaceSelectedListener派生的匿名类'必须被声明为抽象的或实现抽象方法' onError(Status)'在' PlaceSelectionListener'

和另一个错误:

@Override
public void onError(AsyncTask.Status status

其中错误是: 方法不会覆盖其超类中的方法

我能否深入了解如何解决这些错误?

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);
        }
    });


}

}

1 个答案:

答案 0 :(得分:2)

我找到了解决方案: 我改变了:

$(document).ready(function () {
    $('#miTable').DataTable(
        {

            "sAjaxSource": "../DataTable/GetData",

            "aoColumns": [

                { "mDataProp": "Race", "autoWidth": true },
                { "mDataProp": "Year", "autoWidth": true },
                { "mDataProp": "Total", "autoWidth": true }
            ]




        });
});

为:

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