【发布时间】:2014-07-02 17:40:19
【问题描述】:
我想运行一个 ArrayList
ArrayList<Object> lists = new ArrayList<Object>();
lists.add(listType1); //Class Type1 extends ItemProperties
lists.add(listType2); //Class Type2 extends ItemProperties
lists.add(listType3); //Class Type3 extends ItemProperties
for (Object o : lists) {
ArrayList<ItemProperties> al = (ArrayList<ItemProperties>) o;
for (ItemProperties p : al) { //Nullpointer Exception here
if (getString(p.getName()).toLowerCase().contains(arg0.toLowerCase())) {
Drawable icon = getResources().getDrawable(p.getPicture());
TextView tv = new TextView(this);
tv.setTextSize(20);
tv.setTextColor(Color.WHITE);
tv.setGravity(Gravity.CENTER_VERTICAL);
tv.setText(p.getName());
ll.addView(tv); //LinearLayout ll
icon.setBounds(0, 0, tv.getLineHeight() * 3, tv.getLineHeight() * 3);
tv.setCompoundDrawables(icon, null, null, null);
}
}
我怎样才能让它工作?
【问题讨论】:
-
你遇到了什么异常?
-
第 7 行的空指针
-
您的列表是否有可能为空?
-
不,我检查了很多次。
-
好吧,如果你给我们第 7 行,那么应该不难弄清楚那行是什么给了你 NPE。或上下文中使用的其余代码。
标签: java android object arraylist