title: Set ImageView from Bitmap (null pointer exception)
body: <p>So my app has an <code>ActionDialog</code> which contains a blank canvas as the interface with simple cancel and save buttons. What is happening is best demonstrated in a brief illustration</p>
  
  <p>Screen layout before</p>
  
  <p>-(TextView)-(ImageView)-(Button)-</p>
  
  <p>Then when the user presses the button the <code>ActionDialog</code> pops up requesting they sign. Once they sign the captured drawing is saved. Then the drawing is accessed via memory and placed where the original <code>ImageView</code> is with a <code>bitmap</code>. However this is what ends up happening</p>
  
  <p>Screen Layout after</p>
  
  <p>----------nothing--------------</p>
  
  <p>They just disappear and I get an error in my <code>logcat</code>:</p>
  
  <pre><code>05-14 19:06:27.004: E/Error(25274): java.io.FileNotFoundException: /storage/emulated/0signature.png: open failed: EACCES (Permission denied)
  05-14 19:06:27.004: E/BitmapFactory(25274): Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0signature.png: open failed: ENOENT (No such file or directory)
  </code></pre>
  
  <p>java.io.FileNotFoundException: /storage/emulated/0signature.png: open failed: ENOENT (No such file or directory)</p>
  
  <p>It does not crash my program though. Anyways here is the code for the files</p>
  
  <p><strong>action dialog</strong></p>
  
  <pre><code>public class CaptureSignature extends DialogFragment {
  Sign sign;
  View view;
  
  public Dialog onCreateDialog(Bundle savedInstanceState) {
  
      AlertDialog.Builder capSig = new AlertDialog.Builder(getActivity());
  
      capSig.setView(sign = new Sign(this.getActivity(), null))
              .setMessage(R.string.store_question)
              .setPositiveButton(R.string.save,
                      new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int id) {
                              try {
                                  sign.setDrawingCacheEnabled(true);
                                  sign.getDrawingCache()
                                          .compress(
                                                  Bitmap.CompressFormat.PNG,
                                                  10,
                                                  new FileOutputStream(
                                                          new File(
                                                                  getActivity()
                                                                          .getExternalFilesDir(
                                                                                  "img"),
                                                                  "signature.png")));
                              } catch (Exception e) {
                                  Log.e("Error ", e.toString());
                              }
                              File mysig = new File(getActivity()
                                      .getExternalFilesDir("img"),
                                      "signature.png");
                              ImageView sig = (ImageView) getActivity()
                                      .findViewById(R.id.sig_image);
                              Bitmap bmp = BitmapFactory.decodeFile(mysig
                                      .getAbsolutePath());
                              sig.setImageBitmap(bmp);
  
                          }
                      })
  
              .setNegativeButton(R.string.cancel,
                      new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int id) {
                          }
                      });
  
      // Create the Dialog object and return it
      return capSig.create();
  }
  }
  </code></pre>
  
  <p>So obviously I've messed this up somewhere. If anyone has any insight I would be grateful. Thanks!</p>
  
  <p>I personally think I am either saving this wrong or I'm not correctly declaring Sign, as in I call it but I don't give it a value, so the <code>drawing cache</code> is not actually being accessed.</p>
  
  <p><strong>Edit</strong>
  I have declared this in the <code>Manifest</code></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p><strong>2nd Edit</strong> </p>
  
  <p>showing new code and logcat, the error has changed</p>
  
  <p><strong>final edit</strong> </p>
  
  <p>Thank you very much Matt Giles and JRowan, this was driving me insane. It works now and the above code is the final version.</p>