title: How to change ImageView resource in custom ListActivity layout?
body: <p>In my application, I have a ListActivity and a custom layout for it. In the custom layout, I have an ImageView and a TextView. </p>
  
  <p>I want to be able to change the ImageView resource based on some conditional code in my app. However, when I try to <code>image.setImageResource(resource);</code>, I get javaNullPointerException. I have tried placing the code snippet in different places, like after the adapter. Does anyone have any ideas? Thanks in advance.</p>
  
  <p>Also, I did declare the image view before referring to it with <code>ImageView image = (ImageView) findViewById(R.id.image);</code></p>
  
  <p>EDIT:</p>
  
  <p>In my activity:</p>
  
  <pre><code>    setListAdapter(new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, R.id.label, DlistArray));
  
      // Here I want to change the image
    ImageView celebIcon = (ImageView) findViewById(R.id.icon);
    celebIcon.setImageResource(R.drawable.phil);
  
    ListView celebList = getListView();
    registerForContextMenu(getListView());
    celebList.setTextFilterEnabled(true);
  </code></pre>
  
  <p>In my layout:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:cacheColorHint="#00000000"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content" &gt;
  
  &lt;ImageView
      android:id="@+id/icon"
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:layout_marginLeft="10dp"
      android:padding="10dp"
      android:src="@drawable/alan" /&gt;
  
  &lt;TextView
      android:id="@+id/label"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:padding="10dp"
      android:layout_gravity="center_vertical"
      android:text="@+id/label"
      android:textColor="#ffffff"
      android:textSize="20dp" /&gt;
      &lt;/LinearLayout&gt;
  </code></pre>