title: How to display Bitmap image in Dialog by copying it to another Bitmap Object?
body: <p>I am trying to "inflate" or "enlarge" an image that I loaded from a URL into an ImageView. I want to then take the Bitmap that was loaded and store it into a Bitmap Object so that I can call an AlertDialog with another ImageView and set its ImageBitmap to the one I stored. </p>
  
  <p>I used this AsyncTask class to do this: </p>
  
  <pre><code>class DownloadImageTask extends AsyncTask&lt;String, Void, Bitmap&gt; {
  ImageView bmImage;
  
   public DownloadImageTask(ImageView bmImage) {
      this.bmImage = bmImage;
   }
  
   protected Bitmap doInBackground(String... urls) {
      String urldisplay = urls[0];
      Bitmap mIcon11 = null;
      try {
          InputStream in = new java.net.URL(urldisplay).openStream();
          mIcon11 = BitmapFactory.decodeStream(in);
      } catch (Exception e) {
          Log.e("Error", e.getMessage());
          e.printStackTrace();
      }
      return mIcon11;
   }
  
   protected void onPostExecute(Bitmap result) {
      bmImage.setImageBitmap(result);
   }
  }
  </code></pre>
  
  <p>Here is the method in my Activity that I call in onCreate method:</p>
  
  <pre><code>public void loadUI() throws IOException {
      prefs = getSharedPreferences(SELECTED_PREFS, MODE_PRIVATE);
  
      lblEntryNumber = (TextView) findViewById(R.id.lblCEntryNumber);
      lblEntryNumber.setText(cosplayerPrefs.getString(KEY_ENTRY_NUMBER, null));
  
      ImageView imgReference = (ImageView) findViewById(R.id.imgReference);
  
      if (prefs.getString(KEY_REFERENCE_LINK, null).startsWith("http")){
          bImage = new DownloadImageTask((ImageView) findViewById(R.id.imgReference)).execute(cosplayerPrefs.getString(KEY_REFERENCE_LINK, null)).get();
      } else {
          Toast.makeText(ContestantActivity.this, "Invalid URL for Image...", Toast.LENGTH_SHORT).show();
      }
  
      imgReference.setOnClickListener(new View.OnClickListener() {
          Bitmap clone = bImage;
          @Override
          public void onClick(View v) {
              AlertDialog.Builder builder = new AlertDialog.Builder(ContestantActivity.this);
              ImageView imgRefInflated = (ImageView) findViewById(R.id.imgRefInflated);
              imgRefInflated.setImageBitmap(clone);
  
              builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                      dialog.dismiss();
                  }
              });
  
              AlertDialog dialog = builder.create();
              dialog.setContentView(R.layout.dialog_layout);
              dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  
              dialog.show();
          }
      });
  </code></pre>
  
  <p>When I run this, the app runs into some errors in <code>imgRefInflated.setImageBitmap(clone);</code> and I have no clue why. Does anybody have a suggestion about what I could do to resolve this?</p>
  
  <p><strong>EDIT:</strong> It would seem that the ImageView <code>imgRefInflated</code> is returning null, but I don't understand why.</p>