I want to run through an ArrayList<Object> which contains some ArrayList of different types. But each type is extended by ItemProperties with basic information about the type like name and picture (.getName() and .getPicture()).
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);
}
}
How can I get this to work?