title: NullPointerException when using DiskLruCache
body: <p>When I used DiskLruCache I get a NullPointerException:
  First I get a usable cache directory (external if available, internal otherwise) using the following code:</p>
  
  <pre><code>private static File getDiskCacheDir(Context context, String uniqueName) {
      String cachePath;
      if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
              || !Environment.isExternalStorageRemovable()) {
          cachePath = context.getExternalCacheDir().getPath();
      } else {
          cachePath = context.getCacheDir().getPath();
      }
      return new File(cachePath + File.separator + uniqueName);
  }
  </code></pre>
  
  <p>But when I upload my application to the Application Market, I get the error:</p>
  
  <blockquote>
    <p>java.lang.NullPointerException,Attempt to invoke virtual method 'java.lang.String java.io.File.getPath()' on a null object reference,DiskCacheManager.java,47</p>
  </blockquote>
  
  <p>In the DiskCacheManager.java only the above method has the "getPath()".
  It may lead to NullPointerException? What should I do to avoid it?</p>
  
  <p>Sorry, the above method is used in the below function, and the line 47 is:</p>
  
  <blockquote>
    <p>cachePath = context.getExternalCacheDir().getPath();</p>
  </blockquote>
  
  <pre><code>private static DiskLruCache getDiskLruCache(Context context) {
      DiskLruCache mDiskLruCache = null;
      try {
          File cacheDir = getDiskCacheDir(context, "prod");
          if (!cacheDir.exists()) {
              cacheDir.mkdirs();
          }
          mDiskLruCache = DiskLruCache.open(cacheDir, getAppVersion(context), 1, 60 * 1024 * 1024);
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      return mDiskLruCache;
  }
  </code></pre>
  
  <p>Because the crash occured during the test, it may running in the virtual machine, that may cause context.getExternalCacheDir() be null?</p>