gpt4 book ai didi

适配器中的 java.lang.IllegalArgumentException

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

我想列出通过此适配器接收到的 JSON 数据,但是我收到一个错误,指出他没有设法找到 View ,我在日志中收到的错误是“java.lang.IllegalArgumentException: View 不能为空”

  public class categoriaAdapter extends ArrayAdapter {

private List<categoriaModel> categoriaModelList;
private int resource;
private LayoutInflater inflater;

public categoriaAdapter(Context context, int resource, List<categoriaModel> objects) {
super(context, resource, objects);
categoriaModelList = objects;
this.resource = resource;
inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

ViewHolder holder = null;




if (convertView == null){
holder = new ViewHolder();
convertView = inflater.inflate(resource, null);
holder.imgCategoria = (ImageView)convertView.findViewById(R.id.ivIcon);
holder.catTitulo = (TextView)convertView.findViewById(R.id.tvMovie);
holder.catDesc = (TextView)convertView.findViewById(R.id.tvTagline);
holder.catID = (TextView)convertView.findViewById(R.id.tvYear);
convertView.setTag(holder);

} else{
holder = (ViewHolder) convertView.getTag();
}

final ProgressBar progressBar = (ProgressBar)convertView.findViewById(R.id.progressBar);

ImageLoader.getInstance().displayImage(categoriaModelList.get(position).getImage(), holder.imgCategoria, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
progressBar.setVisibility(View.VISIBLE);
}

@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
progressBar.setVisibility(View.GONE);
}

@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
progressBar.setVisibility(View.GONE);
}

@Override
public void onLoadingCancelled(String imageUri, View view) {
progressBar.setVisibility(View.GONE);
}
});



holder.catTitulo.setText(categoriaModelList.get(position).getNome());
holder.catDesc.setText(categoriaModelList.get(position).getDescricacao());
holder.catID.setText(categoriaModelList.get(position).getIdeCategoria());



return convertView;
}

class ViewHolder{
ImageView imgCategoria;
TextView catTitulo;
TextView catDesc;
TextView catID;
}
}

还有我的 Error logs

最佳答案

请检查您的布局 (xml) 并查看 R.id.ivIcon 是否为 imageView 或者它是否存在于 resource 布局中。确保 imgCategoria 不为 null 并且在调用 displayImage 之前已正确初始化。

同时初始化 ImageLoader 配置。即

 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).build();
ImageLoader.getInstance().init(config);
ImageLoader.getInstance().displayImage(categoriaModelList.get(position).getImage(), holder.imgCategoria, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
progressBar.setVisibility(View.VISIBLE);
}

@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
progressBar.setVisibility(View.GONE);
}

@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
progressBar.setVisibility(View.GONE);
}

@Override
public void onLoadingCancelled(String imageUri, View view) {
progressBar.setVisibility(View.GONE);
}
});

希望对你有帮助

关于适配器中的 java.lang.IllegalArgumentException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34446167/

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