title: Android ImageView: Generating Drawable object from local file fails
body: <p>I'm creating an App for displaying images from a previously specified source. I will be downloading these images if a version file has changed. If there is no internet connection available, it will display the local images I have previously downloaded.</p>
  
  <p>For this, I am using an ImageView and Drawable objects like this:</p>
  
  <pre><code>String imageName = Startseite.FILENAME_PRE + "1" + Startseite.FILENAME_POST;
  Drawable d = Drawable.createFromPath(imageName);
  mImageView.setImageDrawable(d);
  </code></pre>
  
  <p>I triple checked via DDMS that the file specified (in this case "page1.jpeg") does indeed exist in the directory "data/data/out.path/files/image1.jpeg". However, in the above code example the second command returns a null object. The file is readable and writable by normal means (streams), but it seems the ImageView doesn't like the image.</p>
  
  <p>I'm not sure how to proceed from here. It could either be that I am missing a crucial security element that allows for the display of images. Or, maybe the image cannot be displayed. Is there a tool to check for displayable images?</p>
  
  <p>Thank you for your time.</p>
  
  <p>Edit 1: I have changed the code to this:</p>
  
  <pre><code>String imageName = Startseite.FILENAME_PRE + "1" + Startseite.FILENAME_POST;
  String imageNameWithPath = getApplicationContext().getFilesDir().getPath() + '/' + imageName;
  Drawable d = Drawable.createFromPath(imageNameWithPath);
  </code></pre>
  
  <p>This creates the Drawable object successfully. Sadly, when assigning the object via SetImageDrawable(), my debugger goes nuts and reads 4 exceptions in classes I have never heard of (most probably some Android interna). I have checked for a double slash (because I copy one to the end), but the path looks clean.</p>
  
  <p>Edit 2: Sadly, the same happens when I create the drawable from a stream and not download the image beforehand.</p>
  
  <p>Edit 3: Here is the LogCat snippet of when the application fails.</p>
  
  <pre><code>06-28 08:14:32.323: WARN/dalvikvm(21462): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
  06-28 08:14:32.323: ERROR/AndroidRuntime(21462): Uncaught handler: thread main exiting due to uncaught exception
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.ourcompany.apps/de.ourcompany.apps.Startseite}: java.lang.NullPointerException
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at android.os.Handler.dispatchMessage(Handler.java:99)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at android.os.Looper.loop(Looper.java:123)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at android.app.ActivityThread.main(ActivityThread.java:4363)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at java.lang.reflect.Method.invokeNative(Native Method)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at java.lang.reflect.Method.invoke(Method.java:521)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at dalvik.system.NativeStart.main(Native Method)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462): Caused by: java.lang.NullPointerException
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at de.ourcompany.apps.Startseite.displayImages(Startseite.java:61)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at de.ourcompany.apps.Startseite.onCreate(Startseite.java:42)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
  06-28 08:14:32.343: ERROR/AndroidRuntime(21462):     ... 11 more
  06-28 08:14:32.373: INFO/Process(64): Sending signal. PID: 21462 SIG: 3
  06-28 08:14:32.373: INFO/dalvikvm(21462): threadid=7: reacting to signal 3
  06-28 08:14:32.373: ERROR/dalvikvm(21462): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
  </code></pre>
  
  <p>I tried the version using the BitmapFactory.decode() method, sadly it results in an exception as well.</p>
  
  <p>What I can add: The following code stems from a video tutorial:</p>
  
  <pre><code>    String mUrlString = "http://www.android.com/images/gingerdroid.png";
      try {
          mImageView.setImageDrawable(
              Drawable.createFromStream(
                      (InputStream) new URL(mUrlString).getContent(), 
                      "qrcode")
          );
      } catch (MalformedURLException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>This code works in the tutorial, yet it exits with the exact same image the same way that my tries do so far.</p>
  
  <p>Hope this helps.</p>
  
  <p>Edit 4: The problem has kinda resolved itself. I created the project anew, copypastad the old source, created the VM anew, suddenly it works. If it was the old project or the VM, I cannot say for sure.</p>