title: Android ArrayList in Application Class
body: <p>I'm trying to pass <code>ArrayList</code>s over the <code>Application</code> class, but when filling these lists, I get a nullpointerexception even if lists are initialized. My application class is :</p>
  
  <pre><code>public class appCyberesa extends Application{
  
      private ArrayList&lt;Marchand&gt; HProviders ;//= new ArrayList&lt;Marchand&gt;();
      private ArrayList&lt;CarAgency&gt; CProviders ;//= new ArrayList&lt;CarAgency&gt;();
      private ArrayList&lt;Agency&gt; Agencies ;//= new ArrayList&lt;Agency&gt;();
      public GeoPoint Tunisie = new GeoPoint(microdegrees(36.80023),microdegrees(10.186073));
      private GeoPoint myLoc;
  
      @Override
      public void onCreate() {
  
  
  
      }
  
      private static int microdegrees(double value){
          return (int)(value*1000000);
      }
  
      public void setMyLoc(GeoPoint myLoc) {
          this.myLoc = myLoc;
      }
  
      public GeoPoint getMyLoc() {
          return myLoc;
      }
  
      public void setHProviders(ArrayList&lt;Marchand&gt; hProviders) {
          HProviders = new ArrayList&lt;Marchand&gt;();
          HProviders.addAll(hProviders);
      }
  
      public ArrayList&lt;Marchand&gt; getHProviders() {
          return HProviders;
      }
  
      public void setCProviders(ArrayList&lt;CarAgency&gt; cProviders) {
          CProviders = new ArrayList&lt;CarAgency&gt;();
          CProviders.addAll(cProviders);
      }
  
      public ArrayList&lt;CarAgency&gt; getCProviders() {
          return CProviders;
      }
  
      public void setAgencies(ArrayList&lt;Agency&gt; agencies) {
          Agencies = new ArrayList&lt;Agency&gt;();
          Agencies.addAll(agencies);
      }
  
      public ArrayList&lt;Agency&gt; getAgencies() {
          return Agencies;
      }
  }
  </code></pre>
  
  <p>and the following is causing the NullPointerException :</p>
  
  <pre><code>appCyberesa myApp = ((appCyberesa)this.getApplication());
  ...
  //the error occurs here
  myApp.setHProviders(Marchands);
  myApp.setCProviders(CarRenters);
  myApp.setAgencies(Agencies);
  </code></pre>
  
  <p>Here's the stacktrace :</p>
  
  <pre><code>09-15 13:59:19.284: ERROR/AndroidRuntime(761): java.lang.RuntimeException: An error occured while executing doInBackground()
  09-15 13:59:19.284: ERROR/AndroidRuntime(761):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
  09-15 13:59:19.284: ERROR/AndroidRuntime(761):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
  09-15 13:59:19.284: ERROR/AndroidRuntime(761):     at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
  09-15 13:59:19.284: ERROR/AndroidRuntime(761):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
  09-15 13:59:19.284: ERROR/AndroidRuntime(761):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
  09-15 13:59:19.284: ERROR/AndroidRuntime(761):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
  09-15 13:59:19.284: ERROR/AndroidRuntime(761):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
  09-15 13:59:19.284: ERROR/AndroidRuntime(761):     at java.lang.Thread.run(Thread.java:1096)
  09-15 13:59:19.284: ERROR/AndroidRuntime(761): Caused by: java.lang.NullPointerException
  09-15 13:59:19.284: ERROR/AndroidRuntime(761):     at com.cyberesa.info.Splash$ProgressTask.doInBackground(Splash.java:70)
  09-15 13:59:19.284: ERROR/AndroidRuntime(761):     at com.cyberesa.info.Splash$ProgressTask.doInBackground(Splash.java:1)
  09-15 13:59:19.284: ERROR/AndroidRuntime(761):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
  09-15 13:59:19.284: ERROR/AndroidRuntime(761):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
  09-15 13:59:19.284: ERROR/AndroidRuntime(761):     ... 4 more
  </code></pre>
  
  <p>and the ligne (Splash.java:70) is : <code>myApp.setHProviders(Marchands);</code></p>
  
  <p>@Peter : Hole splash.java :</p>
  
  <pre><code>package com.cyberesa.info;
  
  
  import java.util.ArrayList;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.util.Log;
  
  public class Splash extends Activity {
      ArrayList&lt;Marchand&gt;Marchands = new ArrayList&lt;Marchand&gt;();
      ArrayList&lt;CarAgency&gt; CarRenters = new ArrayList&lt;CarAgency&gt;();
      ArrayList&lt;Agency&gt; Agencies = new ArrayList&lt;Agency&gt;();
      appCyberesa myApp = ((appCyberesa)this.getApplication());
      MyProgressDialog dialog;
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle icicle) {
          super.onCreate(icicle);
          setContentView(R.layout.splashscreen);
  
          dialog = MyProgressDialog.show(this, null, null);
          new ProgressTask(Splash.this).execute();
      }
  
      private class ProgressTask extends AsyncTask&lt;String, String, Boolean&gt; {
          //private Splash activity;
  
  
          public ProgressTask(Splash splash) {
              //this.activity = splash;
              //context = splash;
          }
  
          /** application context. */
          //private Context context;
  
          protected void onPreExecute() {
  
          }
  
          protected void onCancelled (){
  
          }
  
          @Override
          protected void onPostExecute(final Boolean success) {
              dialog.dismiss();
              Intent newIntent = new Intent(Splash.this, Main.class);
              Splash.this.startActivity(newIntent);
          }
  
  
          protected void onProgressUpdate(String... msg) {
  
           }
  
          protected Boolean doInBackground(final String... args) {
              Log.v("Splash","Loading Hotels providers");
              HComparatorParser HParser = new HComparatorParser();
              Marchands=HParser.parse("t");
              Log.v("Splash","Loading Car providers");
              CComparatorParser CParser = new CComparatorParser();
              CarRenters = CParser.parse(0);
              Log.v("Splash","Travel Agencies");
              AgencyParser AParser=new AgencyParser();
              Agencies=AParser.parse();
              appCyberesa.setHProviders(Marchands);
              appCyberesa.setCProviders(CarRenters);
              appCyberesa.setAgencies(Agencies);
  
              return true;
          }
      }
  }
  </code></pre>