title: getExternalFilesDir(null) throws NullPointerException
body: <p>I am building an Android application and I have chosen to use flat flies in external storage for my persistence method. I have a class that extends Application with some static instance methods. After debugging a few times, I note that none of the instance variables are <code>null</code>, and the <code>NullPointerException</code> is coming from within <code>Context.getExternalFilesDir(null)</code>.</p>
  
  <p>I would like to preface any answers with it is not returning null. Also, I have the correct permissions in my manifest, as well as a check for if the SD card is mounted to the device.</p>
  
  <p>This is the class that holds the call to <code>getExternalFilesDir(null)</code> and throws the error. </p>
  
  <pre><code>public class WhileImOut extends Application {
  
      public static TaskManager taskManager;
      private static Context appContext;
  
      public WhileImOut() {
          super();
          appContext = this;
          initialize();
      }
  
      public static void initialize() {
          if (taskManager == null &amp;&amp; Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
              try{
              File f = appContext.getExternalFilesDir(null); // Exception being thrown here
              taskManager = new TaskManager(f.getAbsolutePath());
              }catch(NullPointerException e){
                  Log.d("Bad","NPE");
              }catch(Exception e){
  
              }
          }
      }
  }
  </code></pre>
  
  <p>This is in my AndroidManifest.xml:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  </code></pre>
  
  <p>Any help would be greatly appreciated. I've been struggling with this for a few hours, and I will take any advice that is given. Thank you</p>
  
  <p>EDIT: LogCat information</p>
  
  <pre><code>10-10 18:55:56.424: E/AndroidRuntime(964): FATAL EXCEPTION: main
  10-10 18:55:56.424: E/AndroidRuntime(964): java.lang.RuntimeException: Unable to resume activity {zsmith.capstone.whileimout/zsmith.capstone.whileimout.TaskListActivity}: java.lang.NullPointerException
  10-10 18:55:56.424: E/AndroidRuntime(964):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2575)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2089)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at android.app.ActivityThread.access$600(ActivityThread.java:130)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at android.os.Handler.dispatchMessage(Handler.java:99)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at android.os.Looper.loop(Looper.java:137)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at android.app.ActivityThread.main(ActivityThread.java:4745)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at java.lang.reflect.Method.invokeNative(Native Method)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at java.lang.reflect.Method.invoke(Method.java:511)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at dalvik.system.NativeStart.main(Native Method)
  10-10 18:55:56.424: E/AndroidRuntime(964): Caused by: java.lang.NullPointerException
  10-10 18:55:56.424: E/AndroidRuntime(964):  at zsmith.capstone.whileimout.TaskListActivity.onResume(TaskListActivity.java:58)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at android.app.Activity.performResume(Activity.java:5082)
  10-10 18:55:56.424: E/AndroidRuntime(964):  at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)
  </code></pre>