title: No such file or directory when caching bitmap?
body: <p>I keep getting this error </p>
  
  <pre><code>07-28 19:32:40.536: ERROR/error(534): java.io.IOException: No such file or directory
  07-28 19:32:40.536: ERROR/error(534):     at java.io.File.createNewFileImpl(Native Method)
  07-28 19:32:40.536: ERROR/error(534):     at java.io.File.createNewFile(File.java:1115)
  07-28 19:32:40.536: ERROR/error(534):     at com.fttech.gameIT.MainMenu.putBitmapInDiskCache(MainMenu.java:447)
  </code></pre>
  
  <p>Here is my putBitmapInDiskCache()</p>
  
  <pre><code>    public void putBitmapInDiskCache(URI imageUri, Bitmap avatar) {   
  
                      File cacheDir = new File(this.getCacheDir(), "thumbnails");    
                      File cacheFile = new File(cacheDir, ""+imageUri.hashCode());     
                      try {      
                      cacheFile.createNewFile();       
                      FileOutputStream fos = new FileOutputStream(cacheFile);    
                      avatar.compress(CompressFormat.PNG, 100, fos);       
                      fos.flush();       
                      fos.close();    
                      } catch (Exception e) {       
                      Log.e("error", "Error when saving image to cache. ", e);    
  
                      }  
  
  
  
                      }
  </code></pre>
  
  <p>EDIT: That worked! Now i get this...</p>
  
  <pre><code>07-28 19:56:31.525: ERROR/DEBUGTAG(573): java.io.FileNotFoundException: /881625833 (No such file or directory)
   07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
    07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:239)
  07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:88)
   07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at java.io.FileInputStream.&lt;init&gt;(FileInputStream.java:122)
   07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at com.fttech.gameIT.MainMenu$ImageAdapter.getView(MainMenu.java:297)
   07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at android.widget.Gallery.makeAndAddView(Gallery.java:748)
   07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at android.widget.Gallery.fillToGalleryLeft(Gallery.java:667)
  </code></pre>
  
  <p>Code i am using to retrieve the images from the cache..</p>
  
  <pre><code>try {
  
  
                                  URL aURL = new URL(myRemoteImages[position]);
  
  
  
                                  URI imageUri = null;
                                  try {
                                      imageUri = aURL.toURI();
                                  } catch (URISyntaxException e1) {
                                      // TODO Auto-generated catch block
                                      e1.printStackTrace();
                                  }
                                  if (new File(new File(myContext.getCacheDir(), "thumbnails"), "" + imageUri.hashCode()).exists())
                                  {
                                      String cachFile = ""+imageUri.hashCode();
                                      FileInputStream fis;
  
                                      try {
                                          fis = new FileInputStream(cachFile);
                                          Bitmap bm = BitmapFactory.decodeStream(fis); 
                                           i.setImageBitmap(bm);
                                              i.setScaleType(ImageView.ScaleType.FIT_CENTER);
                                              /* Set the Width/Height of the ImageView. */
                                              if(Build.VERSION.SDK_INT &gt;= 11){
                                                  i.setLayoutParams(new Gallery.LayoutParams(450, 300));
                                              }
                                              else{
                                                  i.setLayoutParams(new Gallery.LayoutParams(125, 125));
                                              }
  
  
                                      } catch (FileNotFoundException e) {
  
                                             Log.e("DEBUGTAG", "Remtoe Image Exception", e);
  
  
  
  
  
                                              /* Image should be scaled as width/height are set. */
                                              i.setScaleType(ImageView.ScaleType.FIT_CENTER);
                                              /* Set the Width/Height of the ImageView. */
                                              if(Build.VERSION.SDK_INT &gt;= 11){
                                                  i.setLayoutParams(new Gallery.LayoutParams(450, 300));
  
                                              return i;
                                              }
                                                  i.setLayoutParams(new Gallery.LayoutParams(125, 125));
                                                  return i;
                                              }
  </code></pre>