custom ListView --Null pointer exception
- by raghs
this code throws a Null pointer exception. It was thrown by getChildAt(i). The getCount() returns the number of items in listView. But getChildAt(i) returns only if item is present in current list view. For example in a scrollable list view assume that there are 20 items. The getCount() returns 20. But getChildAt(20) returns null. Because it doesnot fit in listview. How to solve this problem??
int i,j=object.getCount();
View v=getListView();
CheckBox chk=null;
for(i=0;i<j;i++)
{
chk=((CheckBox)((ViewGroup) v).getChildAt(i).findViewById(R.id.checkBox1));
if(chk.isChecked())
{
//download the contents to specific folder in sd card
}
}