關於listview.getcount()出現nullpointer exception的解決方案

     最近在作一個手機短信的應用,在羣發功能上會用到listview和checkbox實現聯繫人的多選,一直被一個nullpointer exception的報錯困擾,終於今天在網上找到答案。 spa

for (int i = 0; i <listView.getCount(); i++)
{
//此處採用 listView.getAdapter().getView能夠達到遍歷listview的全部item的效果
//若是採用listView.getcount()就會出現nullpointer報錯
//由於listview.getcount只是獲得當前頁面能夠顯示的listview的item,因此i的值會大於它
CheckBox checkBox = (CheckBox) listView.getAdapter().getView(i, null, null); get

}
it

相關文章
相關標籤/搜索