java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference

getView()方法返回null,会造成这个异常

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportant

改成convertView就行

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    if (convertView == null) {
        convertView = LayoutInflater.from(singleChoiceActivity).inflate(R.layout.single_item,null);
        holder = new ViewHolder();
        holder.tv_data = (TextView) convertView.findViewById(R.id.tv_data);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.tv_data.setText(datas.get(position));
    return convertView;
}

static class ViewHolder {
      TextView tv_data;
}

相关文章:

  • 2021-05-29
  • 2021-04-26
  • 2021-05-18
  • 2021-12-13
  • 2021-09-08
  • 2021-10-16
  • 2021-06-09
  • 2022-01-09
猜你喜欢
  • 2021-05-24
  • 2021-05-31
  • 2021-12-18
  • 2021-12-24
  • 2021-05-15
  • 2021-12-04
  • 2022-12-23
相关资源
相似解决方案