可怕的逻辑错误,ListView中的空指针

来源:互联网 发布:淘宝优惠卷在哪领 编辑:程序博客网 时间:2024/05/21 04:40

我在初始化ListView中的数据的时候,老是报空指针,logcat日志里面也没有提示,我的代码中有错误,每当

adapter.notifyDataSetChanged();

之后就报NULL了,也没有提示你的源代码中有错误。我这里遇到的原因,就是在自定义的Adapter类中,

@Overridepublic View getView(int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubLayoutInflater 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;}


原创粉丝点击