1

I am learning Android (I'm VERY newbie at the moment). I was looking and reading another posts but I have not find this exactly (or not simple). I want to pass a arraylist from an activity to a intent service, I think this is the simplest manner to do it; however I get NullPointer Exception.

public class MainActivity extends Activity {
private static final String TAG = "Main";
ArrayList<String> lista_actual = new ArrayList<String>();
...
    public void onClick (View v) {
    Intent msgIntent = new Intent(MainActivity.this, MiIntentService.class);
    lista_actual.add("probasndo cad");
    lista_actual.add("dfafsadf");
    lista_actual.add("dfasf");
    msgIntent.putStringArrayListExtra("lista", lista_actual);
    msgIntent.putExtra("iteraciones", 10);
    startService(msgIntent);
    //copiar();

}});

Then where I try get the array:

protected void onHandleIntent(Intent intent) 
{

ArrayList<String> lista_archivos = intent.getStringArrayListExtra("lista_actual");
Log.d ("Intent", Integer.toString(lista_archivos.size()));
.
.
.

Thanks.

narco
  • 27
  • 3

2 Answers2

1

While you are fetching your array list in intent service ur calling wrong key, it should be :

ArrayList<String> lista_archivos = intent.getStringArrayListExtra("lista");
Log.d ("Intent", Integer.toString(lista_archivos.size()));

Replace lista_actual with lista.

ZealDeveloper
  • 783
  • 5
  • 21
  • Yes, I see it a few seconds ago (I don't wait for a reply so soon). Thanks, and yes, what stupid!!! :) – narco Mar 15 '14 at 13:19
0

You need to serialize the arraylist in order to pass between activities. Further help will be found here. Hope that helps

Community
  • 1
  • 1
NullPointerException
  • 3,978
  • 4
  • 34
  • 52