【发布时间】:2010-09-06 13:10:37
【问题描述】:
我在列表视图中需要一点帮助。我正在生成一个列表视图,但每当我执行getChildAt(int position) 时,它都会抛出 NullPointerException。
这里是代码
_list=(ListView)findViewById(android.R.id.list);
_loadListElements();
_showListUI();
_list.getChildAt(1).setBackgroundColor(Color.WHITE);
【问题讨论】:
-
空指针异常仅在写入行后
-
将代码分成多行。因此我们可以查看 _list 是否为 null,或者 getChildAt(1) 是否返回 null。
-
实际上没有正确生成列表所有其他的东西也都在工作所以我认为列表中没有问题.....这是一个很长的代码所以我不能把它粘贴到这里.. ..对不起