I'm working on a project which communicate with web server and download some photos. I want these photos to be shown on a listview after the download,but it's throwing me a NullPointerException
. Here is the code I'm using :
private ArrayList <HashMap<String, Object>> items;
private static final String NAMEKEY = "bookname";
private static final String INFOKEY = "bookprice";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mystampii_layout);
}
});
ListView listView = (ListView)findViewById(R.id.mystampii_listview);
items = new ArrayList<HashMap<String,Object>>();
HashMap<String, Object> hm;
final Bitmap b = BitmapFactory.decodeFile("/sdcard/MediaCard2a44bb1f782925923195ee546e7ef395.jpg", null);
ImageView brum = (ImageView) findViewById(R.id.main_img);
brum.setImageBitmap(b);
hm = new HashMap<String, Object>();
hm.put(NAMEKEY, "Moto GP 2010");
hm.put(INFOKEY, "98 Stampii");
items.add(hm);
// Define SimpleAdapter and Map the values with Row view R.layout.listbox
SimpleAdapter adapter = new SimpleAdapter(this, items, R.layout.main_listview,
new String[]{NAMEKEY,INFOKEY}, new int[]{R.id.main_img,R.id.main_name, R.id.main_info});
listView.setAdapter(adapter);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
I know, why I'm getting NullPointerException : because my ImageView brum
is placed in R.layout.main_listview
and I'm setting as Content on this activity R.layout.mystampii_layout
. I really can get the idea how to set the Image from SDCard to a ImageView from another layout.
Any suggestions how can I do that, or how can I show the downloaded image from SDCard in listview.
Thanks really for any kind of help!!!