gpt4 book ai didi

java - 数组适配器() : no suitable constructor found

转载 作者:行者123 更新时间:2023-12-01 12:21:42 25 4
gpt4 key购买 nike

我正在开始 Android 编程。我无法编译我的程序,因为出现以下错误:

错误:没有找到适合 ArrayAdapter() 的构造函数

这是我的个人适配器:

public class StationListAdapter extends ArrayAdapter<Station> {

private ArrayList<Station> stations;
private Context context;
private int resource;
LayoutInflater layoutInflater;

//Constructor - args : (context, resourceId, ArrayList<MyClass>)
public StationListAdapter(Context context, int resource, ArrayList<Station> stations) {

this.context = context;
this.resource = resource;
this.stations = stations;
layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

这是实例适配器的框架部分:

public void onArrayListReady(ArrayList<Station> stations) {
TextView textView = (TextView) this.view.findViewById(R.id.fragment_list_textview);
ListView listView = (ListView) this.view.findViewById(R.id.fragment_list_stations_list);
adapter = new StationListAdapter(getActivity(), R.layout.fragment_list_row, stations);
listView.setAdapter(adapter);
}

最佳答案

您需要从构造函数中调用 super 构造函数才能正确初始化适配器。

关于java - 数组适配器() : no suitable constructor found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26620275/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com