Reputation: 2866
I was trying to create a application where i parse JSON data and have thumbnails generated & a List View. Something very similar to the TED app, look at screenshot below :
https://lh6.ggpht.com/52KEhYtmJE-IV7yfMyAF9JZ1K4nTZGsZ-KM1eQG4-yMmlTqv-KaL7b1JE7I2W3wNVw
I was able to succesfully add a Header to my List View using :
View header = getLayoutInflater().inflate(R.layout.header, null);
list.addHeaderView(header);
list.setAdapter(adapter);
The header xml file in layout folder contains a ImageView,i have found the id using
iv=(ImageView) findViewById(R.id.ivback);
But my problem is whenever i try to set it to any image , i get a Null Pointer Exception, Loggging it showed that iv is null.
Any idea why iv is null ? since iv is null , iv.setImage() methods dont work.
Thanks in advance
I also confirmed that the link of image i am passing is not null
So how do i set a image to that imageview i have added as a header to my list?
Upvotes: 0
Views: 525
Reputation: 15973
it is null as you should get the image view from the header view not the view of the activity..it should be like:
iv=(ImageView) header.findViewById(R.id.ivback);
Upvotes: 1