I'm getting a null pointer exception on the following code. Any idea why?
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;
}
}
Thanks, Tom
If it helps there is a similar question here: CodeLearn Twitter Tutorial nullpointer error on TweetAdapter.java (however I couldn't get this fix to work)