我写了以下代码:
TodosOverviewActivity extends ListActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.todo_list);
this.getListView().setDividerHeight(2);
registerForContextMenu(getListView());
fillData();
}
private void fillData() {
fetchEvents();
adapter2 = new MySimpleArrayAdapter
(this, nameOfEvent, startDates, descriptions);
setListAdapter(adapter2);
}
public class MySimpleArrayAdapter extends ArrayAdapter<String> {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.todo_list, parent, false);
TextView titleTextView = (TextView) rowView
.findViewById(R.id.todo_row_title);
TextView dateTextView = (TextView) rowView
.findViewById(R.id.todo_row_date);
ImageView imageView = (ImageView) rowView
.findViewById(R.id.todo_row_image);
titleTextView.setText(mTitles[position]);
..
}
但是它在 nullpointer 上失败titleTextView
。我错过了什么?