空指针异常ListAdapter

时间:2015-06-16 07:37:08

标签: java android

我在以下代码中遇到空指针异常。知道为什么吗?

public class TweetAdapter extends ArrayAdapter<Tweet>{

    private LayoutInflater inflater;
    private Context context;
    private List<Tweet> values;

    public TweetAdapter(Activity activity, List<Tweet> tweets){
        super(activity, R.layout.row_tweet, tweets);
        inflater = activity.getWindow().getLayoutInflater();

        context = this.getContext();
        values = tweets;
    }

    @SuppressLint("ViewHolder") @Override
    public View getView(int position, View convertView, ViewGroup parent){
        LayoutInflater inflater = (LayoutInflater)  context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.row_tweet, parent, false);
//The exception is here
        TextView headerView = (TextView) rowView.findViewById(R.id.header);
        TextView bodyView = (TextView) rowView.findViewById(R.id.tweetBody);
        headerView.setText(values.get(position).getTitle());
        bodyView.setText(values.get(position).getBody());
        return rowView;
    }

}

谢谢, 汤姆

如果它有帮助,这里有一个类似的问题:CodeLearn Twitter Tutorial nullpointer error on TweetAdapter.java(但是我无法让这个修复工作)

0 个答案:

没有答案