gpt4 book ai didi

java - ResourceNotFoundException ListView 适配器

转载 作者:行者123 更新时间:2023-11-30 11:04:11 25 4
gpt4 key购买 nike

我为 ListView 项创建了一个构造函数DataPembeli,然后创建了自定义 ListView 适配器DataPembeliListAdapter并使用这样的构造函数:

txtid.setText(dataPembeliItems.get(position).getId()); // THIS IS THE ERROR LINE  
txtket1.setText(dataPembeliItems.get(position).getNama());
txtket2.setText(dataPembeliItems.get(position).getAlamat());
txtket3.setText(dataPembeliItems.get(position).getNohp());

DataPembeliFragment 类中,我是这样使用它的:

public class DataPembeliFragment extends Fragment {

private ListView listPembeli;
private ImageButton btnTambah;

// slide data items
private int[] idDataPembeli;
private String[] namaDataPembeli, alamatDataPembeli, noHpDataPembeli;

private ArrayList<DataPembeli> dataPembeliItems;
private DataPembeliListAdapter adapter;

public DataPembeliFragment(){}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.fragment_data_pembeli, container, false);

listPembeli = (ListView) rootView.findViewById(R.id.list_sliderdata);
btnTambah = (ImageButton) rootView.findViewById(R.id.btnTambah);
btnTambah.setOnClickListener(new View.OnClickListener(){

@Override
public void onClick(View view) {
showEditDialog();
}
});

dataPembeliItems = new ArrayList<DataPembeli>();
idDataPembeli = new int[10];
namaDataPembeli = new String[10];
alamatDataPembeli = new String[10];
noHpDataPembeli = new String[10];

idDataPembeli[0] = 1;
namaDataPembeli[0] = "ryno";
alamatDataPembeli[0]= "padang";
noHpDataPembeli[0] = "0812874512";

dataPembeliItems.add(new DataPembeli(idDataPembeli[0], namaDataPembeli[0], alamatDataPembeli[0], noHpDataPembeli[0]));

idDataPembeli[1] = 2;
namaDataPembeli[1] = "yezu";
alamatDataPembeli[1]= "padang";
noHpDataPembeli[1] = "0819232211";

dataPembeliItems.add(new DataPembeli(idDataPembeli[1], namaDataPembeli[1], alamatDataPembeli[1], noHpDataPembeli[1]));

idDataPembeli[2] = 3;
namaDataPembeli[2] = "test";
alamatDataPembeli[2]= "padangs";
noHpDataPembeli[2] = "0819232xx";

dataPembeliItems.add(new DataPembeli(idDataPembeli[2], namaDataPembeli[2], alamatDataPembeli[2], noHpDataPembeli[2]));

listPembeli.setOnItemClickListener(new SlideMenuClickListener());

adapter = new DataPembeliListAdapter(getActivity().getApplicationContext(),dataPembeliItems);
listPembeli.setAdapter(adapter);

return rootView;
}

当我调用 Fragment 时,我在上面标记的行的 DataPembeliAdapter 的 logcat 中得到了 ResourceNotFoundException。(在注释“//THIS IS THE ERROR LINE”)

最佳答案

setText 方法需要 String 参数来显示,但是你放置的是 int 值,所以他试图从资源中获取字符串。您只需要 txtid.setText(Integer.toString(dataPembeliItems.get(position).getId()))

关于java - ResourceNotFoundException ListView 适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30095193/

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