n4h1n n4h1n - 6 months ago 16
Android Question

Passing ArrayList<CustomObject> Between Activities

i've implemented a Parcelable class:

public class Evento implements Parcelable {
private int;
private String ;
private String imagen;
//more atts

//Constructors, setters and getters

public Evento(Parcel in) {
this.id = in.readInt();
this.titulo = in.readString();

public void writeToParcel(Parcel dest, int flags) {
public static final Parcelable.Creator<Evento> CREATOR = new Parcelable.Creator<Evento>() {
public Evento createFromParcel(Parcel in) {
return new Evento(in);

public Evento[] newArray(int size) {
return new Evento[size];

In my activity, i'm trying to pass an arrayList to an other activitie:
I'me overwriten onItemClick and i'm passing the information this way:

public void onItemClick(AdapterView<?> a, View v, int position, long id) {
//create new activitie
ArrayList<Eventos> eventos = new ArrayList<Eventos>();
Intent intent = new Intent(QueActivity.this, ProductosCategorias.class);

//Create information
Bundle informacion= new Bundle();
informacion.putParcelableArrayList("eventos", eventos);

and receiving it in the other activity:

protected void onCreate(Bundle savedInstanceState) {
lv = (ListView) findViewById(R.id.listaCategoriaElegida);
Bundle informacionRecibida = getIntent().getExtras();
ArrayList<Evento> eventos =new ArrayList<Evento>();
eventos= informacionRecibida.getParcelableArrayList("eventos");

I'm getting a null pointer exception. I've debbuged it and i'm getting NULL when i execute the getParcelableArrayList("eventos"), i mean, my arraylist eventos is null, so, i'm receiving no information.

Any help will be great


This code

Bundle informacion= new Bundle();
informacion.putParcelableArrayList("eventos", ArrayList<Eventos> eventos);

Should be

Bundle informacion = new Bundle();
ArrayList<Eventos> mas = new ArrayList<Eventos>();
informacion.putSerializable("eventos", mas);

and Make sure your Eventos structure like a serializable object

private class Eventos implements Serializable {


Reading Values

ArrayList<Eventos> madd=getIntent().getSerializableExtra(key);