Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8656085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:11:31+00:00 2026-06-12T15:11:31+00:00

I am building an Android application and I have chosen to use flat flies

  • 0

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 null, and the NullPointerException is coming from within Context.getExternalFilesDir(null).

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.

This is the class that holds the call to getExternalFilesDir(null) and throws the error.

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 && 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){

            }
        }
    }
}

This is in my AndroidManifest.xml:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

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

EDIT: LogCat information

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:11:33+00:00Added an answer on June 12, 2026 at 3:11 pm

    You are doing your initialization in the constructor; this will not work. You should be doing your initialization in onCreate(). When the constructor is invoked, the context has not been properly initialized.

    public class WhileImOut extends Application {
    
        public static TaskManager taskManager;
        private static Context appContext;
    
        public void onCreate() {
            super();
            appContext = this;
            initialize();
        }
    
        public static void initialize() {
            if (taskManager == null && 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){
    
                }
            }
        }
    }
    

    (By the way, is there any reason to have a separate initialize() method? If so, is there any reason for it to be public?)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an android application that uses several third party libraries. I have
Building an Android application using Google's GCM service. I have implemented the onRegistered method
I am building an Android application that requires OAuth. I have all the OAuth
I am building an android application that reads text files. Now,i have multiple text
In the android application that we are building, we would like to have a
I have an android application in which I take a photo.For that I'm building
i'm building an android application which have a chat. in this chat i each
Helo. I am building an application for kids using Phonegap. On Android I have
I'm building an Android application that's based around an enhanced WebView (based on PhoneGap).
I'm building an application for Android devices that requires it to recognize, by accelerometer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.