我正在直接解释我的问题。请参阅下面的代码片段。Listview中的问题自定义适配器类
@Override
public View getView(int index, View convertView, ViewGroup parent) {
Comments comment = comments.get(index);
if (convertView == null) {
LayoutInflater inflator = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflator.inflate(R.layout.comment_row, null);
}
TextView tvAuthor = (TextView) convertView.findViewById(R.id.commentAuthor);
System.out.println("tvAuthor"+tvAuthor);
tvAuthor.setText(comment.getAuthor());
convertView.setTag(comment);
return convertView;
}
我为tvAuthor得到空。因此,在我尝试设置文本的紧接着的下一行中,我收到空指针异常。
我已经在xml中正确声明了commentAuthor。我无法追踪,从这个错误弹出。专家,请给予帮助。
对这方面的帮助很受赞赏。
期待, 问候, 罗尼
看起来它无法找到commentViewAuthor里面的convertView你应该发布你的comment_row xml。你也可以使用静态的View.inflate()它的一个小捷径。 – schwiz 2010-10-31 18:12:36
@ user264953:“我已经在xml中正确声明了commentAuthor。” - 请发布布局XML。 – CommonsWare 2010-10-31 18:31:23