I have a custom listview I am using with a custom adapter. When the app opens initially the first few items are shown properly. However, when I start to scroll down, I get a nullPointerException in the getView() method:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ListViewItem item = items.get(position);
View vi = convertView;
if (item.Type.equals("Homework")) {
if (convertView == null)
vi = inflater.inflate(R.layout.item_row_homework, null);
ImageView imgThumbnail = (ImageView) vi
.findViewById(R.id.homework_imgThumbnail);
TextView txtTitle = (TextView) vi
.findViewById(R.id.homework_txtTitle);
TextView txtSubTitle = (TextView) vi
.findViewById(R.id.homework_txtSubTitle);
imgThumbnail.setImageResource(item.ThumbnailResource);
txtTitle.setText(item.Title);
txtSubTitle.setText(item.SubTitle);
}
if (item.Type.equals("Study")) {
if (convertView == null)
vi = inflater.inflate(R.layout.item_row_study, null);
ImageView imgThumbnail = (ImageView) vi
.findViewById(R.id.study_imgThumbnail);
TextView txtTitle = (TextView) vi
.findViewById(R.id.study_txtTitle);
TextView txtSubTitle = (TextView) vi
.findViewById(R.id.study_txtSubTitle);
imgThumbnail.setImageResource(item.ThumbnailResource);
txtTitle.setText(item.Title);
txtSubTitle.setText(item.SubTitle);
}
if (item.Type.equals("Project")) {
if (convertView == null)
vi = inflater.inflate(R.layout.item_row_project, null);
ImageView imgThumbnail = (ImageView) vi
.findViewById(R.id.project_imgThumbnail);
TextView txtTitle = (TextView) vi
.findViewById(R.id.project_txtTitle);
TextView txtSubTitle = (TextView) vi
.findViewById(R.id.project_txtSubTitle);
imgThumbnail.setImageResource(item.ThumbnailResource);
txtTitle.setText(item.Title);
txtSubTitle.setText(item.SubTitle);
}
return vi;
}
and it comes in any of the three instances of the line
imgThumbnail.setImageResource(item.ThumbnailResource);
I have looked at other SO questions on this but have not understood exactly what is going on.
Thanks.