Reputation: 3078
I have an imageview in a layout called footer.xml which is actually added as footer for the listview.I need to dynamically display images at the end of the listview.So i have referred the imageview in my java file as below
ImageView footerimage;
View footerView = getLayoutInflater().inflate(R.layout.footer, null);//This is the footer layout which i have added to the listview
footerimage = (ImageView)findViewById(R.id.im);
footerimage.setBackgroundResource(images[i]);//images is an integer array which has drawable resources and i value is not null.
lv.addFooterView(footerView, null, false);
I'm getting a null pointer exception in the fourth line of the above code.I have also changed the images[i] to R.drawable.someimage but the NPE still exist. Below is my footer Layout
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="@+id/im"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:contentDescription="@string/app_name" />
Any suggestions are appreciated.Thanks in advance
Upvotes: 1
Views: 1207
Reputation: 6318
I guess it should be:
footerimage = (ImageView) footerView.findViewById(R.id.im);
Upvotes: 7