ImageView variable returning null even after defined; Android
<p>In my program I am trying to display an image from a file using an ImageView. I have declared the ImageView to be related to an ImageView XML file and have set the value to be an image from a file using BitmapFactory. After all this, I still am receiving a NullPointerException because the ImageView variable is apparently still null. If you have any ideas or advice, please let me know, thanks!</p>

<p>Here's the code I am talking about:</p>

<pre><code>public void imageViewMethod(String file){
    Logger log = Logger.getLogger("com.example.myclass");

    try {

    File fileName = new File(root, file);
    if(fileName.exists()){
    String dirFileName = fileName.toString();
    Toast.makeText(getApplicationContext(), dirFileName, Toast.LENGTH_LONG).show();
    ImageView iv = (ImageView)findViewById(R.id.image);

    iv.setImageBitmap(BitmapFactory.decodeFile(dirFileName));
    super.setContentView(iv);
    }
    }catch(Exception e){
        Toast.makeText(getApplicationContext(), "Hit Exception", Toast.LENGTH_LONG).show();
        log.log(Level.SEVERE, "uncaught exception", e);
    }
}
</code></pre>

<p>And the corresponding XML file:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 

android:layout_margin="5dp"&gt;
&lt;/ImageView&gt;
</code></pre>
