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 8058425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:21:20+00:00 2026-06-05T09:21:20+00:00

I’m trying to track down a new null pointer exception which is appearing in

  • 0

I’m trying to track down a new null pointer exception which is appearing in my ACRA logs and which I can’t reproduce. Here’s the relevant code:

public class MyApplication extends Application {
   public void onCreate() {
       DataManager.instance().initializeData(this);
   }
}

public class DataManager {
    private static DataManger instance = new DataManger();
    private List<DataModel> dataModels;
    private List<I_Callback> callbacks = new ArrayList<I_Callback>();
    private boolean isInitialized = false;

    private DataManager(){}

    public static DataManager instance() {
       return instance;
    }

    public void initializeData(Context context) {
        new DataManagerInitializer().execute(context);
    }

    public void setDataModels(List<DataModel> models) {
        dataModels = models;
    }

    public void synchronized registerInitializeCallbacks(I_Callback callback) {
        if (isInitialized) {
             callback.executeCallback();
        } else {
             callbacks.add(callback);
        }
    }

    public void synchronized setInitialized() {
        isInitialized = true;
        for (I_Callback callback:callbacks) {
             callback.executeCallback();
        }
        callbacks.clear();
    }
}

public class DataManagerInitializer extends AsyncTask<Context, Void, Void>{
    protected Void doInBackground(Context... contexts){
        List<DataModel> dataModels = new ArrayList<DataModel>();
        /*various code to create DataModel objects and add to dataModels list*/
        DataManager.instance().setDataModels(dataModels);
        return null;
    }

    protected void onPostExecute(Void result) {
        DataManager.instance().setInitialized();
    }
}

public class ActivityA extends Activity implements I_Callback{
     public void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.graphical_layout);
        DataManager.instance().registerInitializeCallbacks(this);
     }

     public void executeCallback() {
        /* wire up button to call Activity B */
     }
}

public class ActivityB extends Activity {
     public void onCreate(Bundle savedInstanceState) {
         List<DataModel> dataModels = DataManager.instance().getDataModels();

         /* The following line of code throws a null pointer exception 
            in the stack trace*/
         for (int i=0; i < dataModels.size(); i++){
              /* do something with the data model */
         }
     }
}

To break down the above more simply, the application is launched which kicks off the initializion of the data manager singleton. ActivityA, the main activity, launches and waits for the data manager to complete initialization before allowing any actions, wiring up any events, etc. From ActivityA, its not possible to get to ActivityB without the call back method executing and ActivityB is only reachable from ActivityA. The only way for the list of data models to be null in the DataManager is for it to not have been initialized, but I’m struggling to see how this is possible. Any suggestions on how my null pointer may have occurred?

  • 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-05T09:21:22+00:00Added an answer on June 5, 2026 at 9:21 am

    Let’s assume that:

    you are interacting with the Activity B
    

    press the home button:

    start playing with other apps (consuming memory)
    

    at some point the so needs memory and it’s gonna start garbage collecting objects, included your “instance”.

    If that happens when you launch your app the framework will resume the activity B and the npe will happen.

    You need to re-create the instance (in the activity B) if it is null.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words

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.