我在初始化ListView中的数据的时候,老是报空指针,logcat日志里面也没有提示,我的代码中有错误,每当
adapter.notifyDataSetChanged();
之后就报NULL了,也没有提示你的源代码中有错误。我这里遇到的原因,就是在自定义的Adapter类中,
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) this.mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.listview, null);
ImageView imageView = (ImageView) convertView
.findViewById(R.id.iv_listView_img);
TextView drugsName = (TextView) convertView
.findViewById(R.id.tv_listView_title);
TextView drugsProduction = (TextView) convertView
.findViewById(R.id.tv_listView_content);
DrugsEntity drugs = getList().get(position);
imageView.setImageResource(R.drawable.item_drugs_ico);
drugsName.setText(drugs.getName());
drugsProduction.setText(drugs.getProduction());
return null;//原因出在这里,应该改为return convertView;
}