-1

当我将 id 设置为 textview 时,它会抛出 Nullpointer Exception.on 这一行。-holder.id.setText(c.getListId());holder.id.setVisibility(View.VISIBLE);-

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

    if (DEBUG) Log.d(TAG, "start getView()");

    final ViewHolder holder;
    View v = convertView;

    if(v == null){
         if (DEBUG) Log.d(TAG, "mInflater inflate mylistrow");
         v = mInflater.inflate(layoutResource, null);
         if (DEBUG) Log.d(TAG, "set up viewHolder");
         holder = new ViewHolder();

         holder.id = (TextView)v.findViewById(R.id.custid);
         holder.column1 = (CheckBox)v.findViewById(R.id.column1);
         holder.column2 = (TextView)v.findViewById(R.id.column2);
         holder.column3 = (TextView)v.findViewById(R.id.column3);
         holder.column4 = (TextView)v.findViewById(R.id.column4);
         holder.column5 = (TextView)v.findViewById(R.id.column5);
         holder.column6 = (TextView)v.findViewById(R.id.column6);
         holder.column7 = (TextView)v.findViewById(R.id.column7);

         holder.column1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (DEBUG) Log.d(TAG, "ID "+holder.id.getText()+" clicked: "+isChecked);
                int id = Integer.valueOf((String) holder.id.getText());
                checkedList.remove(id);
                checkedList.put(id, isChecked);

                if(isChecked==false&&checkAllBox.isChecked()){cancelSetCheckedAll=true;checkAllBox.setChecked(false);}
            }
        });

         if (DEBUG) Log.d(TAG, "attach viewHolder to convertview");
         v.setTag(holder);
    }else{
        holder = (ViewHolder)v.getTag();
    }

    Feedback c = data.get(position);
    if (DEBUG) Log.d(TAG, "Position "+position);
    if(c != null){

        holder.id.setText(c.getListId());
        holder.id.setVisibility(View.VISIBLE);

        int id = Integer.valueOf(c.getListId());
        if(checkedList.containsKey(id)){
            holder.column1.setChecked(checkedList.get(id));
        }else{
            holder.column1.setChecked(false);
        }
        holder.column1.setVisibility(View.VISIBLE);

        holder.column2.setText(c.getName());
        holder.column2.setVisibility(View.VISIBLE);

        holder.column3.setText(c.getEmail());
        holder.column3.setVisibility(View.VISIBLE);

        holder.column4.setText(c.getSex());
        holder.column4.setVisibility(View.VISIBLE);

        holder.column5.setText(c.getFeedbackType());
        holder.column5.setVisibility(View.VISIBLE);

        holder.column6.setText(c.getFeedback());
        holder.column6.setVisibility(View.VISIBLE);

        holder.column7.setText(c.getEmailRes());
        holder.column7.setVisibility(View.VISIBLE);

    }else{
        if (DEBUG) Log.d(TAG, "t is null");
        holder.id.setVisibility(View.GONE);
        holder.column1.setVisibility(View.GONE);
        holder.column2.setVisibility(View.GONE);
        holder.column3.setVisibility(View.GONE);
        holder.column4.setVisibility(View.GONE);
        holder.column5.setVisibility(View.GONE);
        holder.column6.setVisibility(View.GONE);
    }
    if (DEBUG) Log.d(TAG, "return v");
    return v;
}
4

1 回答 1

1

我不确定,但尝试将您的行更改为以下内容:

holder.id.setText(String.valueOf(c.getListId()));
于 2012-07-13T07:43:22.330 回答