title: Bitmap cannot be created from an image file
body: <p>As part of my program, I need to show images belonging to a folder (JPG files). To accomplish that, I have this code:</p>
  
  <pre><code>private ArrayList&lt;ImageGalleryItem&gt; getData() {
      final ArrayList&lt;ImageGalleryItem&gt; imageItems = new ArrayList&lt;&gt;();
      try {
          Intent intent = getIntent();
          String imagesFolder = intent.getStringExtra("SourceFolder");
          String questionId = Integer.toString(intent.getIntExtra("QuestionId", 0));
          File file = new File(imagesFolder);
          if (file.exists() &amp;&amp; file.isDirectory()) {
              File[] files = file.listFiles();
              for (File f : files) {
                  try {
                      if (f.getName().startsWith(questionId + "_")) {
                          Bitmap bitmap = BitmapFactory.decodeFile(f.getPath());
                          imageItems.add(new ImageGalleryItem(bitmap, f.getName()));
                      }
                  }
                  catch (Exception e)
                  {
                      Log.e("TDC@", e.getMessage());
                  }
              }
          }
      }
      catch (Exception e)
      {
          Log.e("TDC@", e.getMessage());
      }
  
      return imageItems;
  }
  </code></pre>
  
  <p>The instruction "BitmapFactory.decodeFile(f.getPath());" creates the bitmap files for all files but for one of them. When that code is reached for the conflicting file, decodeFile throws an exception, but the stranger thing is that the exception is not catched by the try catch block.</p>
  
  <p>When debugging using F7, the exception is thrown in BitmapFactory.java, in the throw shown in this code:</p>
  
  <pre><code>    try {
          bm = nativeDecodeByteArray(data, offset, length, opts);
  
          if (bm == null &amp;&amp; opts != null &amp;&amp; opts.inBitmap != null) {
              throw new IllegalArgumentException("Problem decoding into existing bitmap");
          }
          setDensityFromOptions(bm, opts);
      } finally {
          Trace.traceEnd(Trace.TRACE_TAG_GRAPHICS);
      }
  </code></pre>
  
  <p>So the questions are, why the bitmap cannot be correctly decoded and why the exception is not catched.</p>
  
  <p>If I browse for the file in mobile file manager, and open the file, it is shown correctly, so, there is no problem with the image format. Furthermore, this image was taken with the camera, the same as the other images that do decode correctly.</p>
  
  <p>How to solve this problem or, is there an alternate way to do this?</p>