NullPointerException异常与simpleAdapter在android系统 [英] NullPointerException with simpleAdapter in android
问题描述
我使用的是simpleAdapter创建一个列表视图,但是我得到这个错误:
I am using a simpleAdapter to create a listview, however I get this error:
Caused by: java.lang.NullPointerException
at com.tab.Activity.onCreate(Activity.java:36)
和这个code,我现在用:
and this the code that I am using:
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
private SimpleAdapter notes;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
notes = new SimpleAdapter(
this,
list,
R.layout.display_layout,
new String[] { "line1" },
new int[] { R.id.text1} );
ListView lv = (ListView) findViewById(R.id.listview);
lv.setAdapter( notes );
}
第36行是
new int[] { R.id.text1} );
text1的定义,所以为什么我收到空指针错误?
text1 is defined, so why I am getting nullpointer error?
推荐答案
最后,我通过实施以下这个教程新SimpleAdapter解决该问题:
的http://kurtchen.com/blog/2010/07/30/use-simpleadapter-to-make-a-list-with-icons/
Finally, I solved the issue by implementing new SimpleAdapter following this tutorial: http://kurtchen.com/blog/2010/07/30/use-simpleadapter-to-make-a-list-with-icons/
我觉得问题是,ArrayList的名单变量为空,因此SimpleAdapter不能映射到R.id.text1列中的任意值。
I think the problem was that "ArrayList list" variable was null and therefore SimpleAdapter could not map any value to the "R.id.text1" column.
感谢大家对你的答案
这篇关于NullPointerException异常与simpleAdapter在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!