0

I want to use a Adapter and a ArrayList declared in Inicio.java from a Service for example:

In Inicio.java

public static AdaptadorImagenes adaptador;
public static ArrayList<String> pathImagenes;

    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.layout_incio);

            if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.HONEYCOMB_MR2) {
                ActionBar actionBar = getActionBar();
                actionBar.hide();

            }
            contexto = getApplicationContext();
            datos = new ArrayList<Integer>();
            pathImagenes = new ArrayList<String>();

            recojeDatosDeSesion(savedInstanceState);
            adaptador = new AdaptadorImagenes(contexto);

And service.java

                Inicio.pathImagenes.add(pathImagen);

The activity start the service, but when i try to do Inicio.pathimagenes this return me nullpointer exception.

colymore
  • 11,776
  • 13
  • 48
  • 90
  • Don't try to use objects that belong to an Activity in a Service. So something like http://stackoverflow.com/questions/4300291/example-communication-between-activity-and-service-using-messaging – zapl Nov 22 '12 at 16:09

1 Answers1

1

Just initialize the list at declaration (not in onCreate):

public static ArrayList<String> pathImagenes = new ArrayList<String();
sdabet
  • 18,360
  • 11
  • 89
  • 158
  • public static AdaptadorImagenes adaptador = new AdaptadorImagenes(); No enclosing instance of type Inicio is accessible. Must qualify the allocation with an enclosing instance of type Inicio (e.g. x.new A() where x is an instance of Inicio). Yes but for the adapter? Before works for me but i dont know how i had change.. – colymore Nov 22 '12 at 15:44