custom ListView --Null pointer exception

Posted by raghs on Stack Overflow See other posts from Stack Overflow or by raghs
Published on 2012-04-13T01:22:11Z Indexed on 2012/04/13 5:29 UTC
Read the original article Hit count: 199

Filed under:
|
|
|

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
            }
        }

© Stack Overflow or respective owner

Related posts about java

Related posts about android