Null pointer on imageview.setBackgroundResource
<p>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</p>

<pre><code>    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);
</code></pre>

<p>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</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
</code></pre>

<p></p>

<pre><code>&lt;ImageView
    android:id="@+id/im"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"        
    android:contentDescription="@string/app_name" /&gt;
</code></pre>

<p></p>

<p>Any suggestions are appreciated.Thanks in advance</p>
