i get a fragment with listview inside another fragment,and the listview have a viewholder class like this:
private class ViewHolder{
TextView rowText1;
TextView rowText2;
}
and give the textview very simple task:
holder.rowText1.setText(someString);
holder.rowText2.setText(someString);
The Log give me a nullpointer error:
java.lang.NullPointerException:
Attempt to invoke virtual method void android.widget.TextView.setText(java.lang.CharSequence) on a null object reference
But if i just give one view settext(any one), everything works fine:
holder.rowText1.setText(someString);
//holder.rowText2.setText(someString);
Any ideas why?
My viewholder code:
public View getView(int position, View convertView, ViewGroup parent) {
int type = getItemViewType(position);
ViewHolder holder;
if(convertView == null){
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.some_layout, parent,false);
switch(type){
case 1:
holder.rowText1 = (TextView) convertView.findViewById(R.id.textView1);
break;
case 2:
holder.rowText1 = (TextView) convertView.findViewById(R.id.textView1);
holder.rowText2 =(TextView)convertView.findViewById(R.id.textView2);
ImageView fileImage = (ImageView)convertView.findViewById(R.id.typeImage);
fileImage.setImageDrawable(fileDrawable);
break;
}
convertView.setTag(holder);
}else {
holder = (ViewHolder) convertView.getTag();
}
Also,i dug a little bit ,find the problem seems to be in the view recycle stage,somehow when the system began to recycle the view ,with two views,it just doesnt work.