Skip to content Skip to sidebar Skip to footer

Android ArrayList In Application Class

I'm trying to pass ArrayLists over the Application class, but when filling these lists, I get a nullpointerexception even if lists are initialized. My application class is : public

Solution 1:

Why do you need to create an empty list and add items again?? Also hProviders is it null when setting??

public void setHProviders(ArrayList<Marchand> hProviders) {
        HProviders = hProviders;
}

Solution 2:

This line produces NullPointerException:

HProviders.addAll(hProviders);

because Marchand is null when you call

myApp.setHProviders(Marchands);

Make sure Marchand is not null, or better, follow advice of Teja Kantamneni.


Solution 3:

You need to initialize the variable myApp in onCreate(). You are currently initializing this variable when the instance is created, like this:

appCyberesa myApp = ((appCyberesa)this.getApplication());

The problem is that at the time the instance of Splash is created, a call to getApplication() will return null because the necessary underlying framework hasn't been set up yet (this all happens in the constructor before onCreate() is called). Just move the initialization to onCreate() and you will be good.


Post a Comment for "Android ArrayList In Application Class"