1

I am sending an object from an antivity to other. the class is:

public class Reparacion implements Parcelable {

private int tipo;
private int estado;
private int id;

private String razonSocial;
private String direccion;
private String contacto;
private String telefono;
private String detalle;

public Reparacion() {

}

public Reparacion(int tipo, int estado, int id, String razSoc, String dir,
        String contacto, String tfno, String detalle) {
    this.tipo = tipo;
    this.estado = estado;
    this.id = id;
    this.razonSocial = razSoc;
    this.direccion = dir;
    this.contacto = contacto;
    this.telefono = tfno;
    this.detalle = detalle;
}

public String getContacto() {
    return contacto;
}

public void setContacto(String contacto) {
    this.contacto = contacto;
}

public String getTelefono() {
    return telefono;
}

public void setTelefono(String telefono) {
    this.telefono = telefono;
}

public String getDetalle() {
    return detalle;
}

public void setDetalle(String detalle) {
    this.detalle = detalle;
}

public int getTipo() {
    return tipo;
}

public void setTipo(int tipo) {
    this.tipo = tipo;
}

public String getRazonSocial() {
    return razonSocial;
}

public void setRazonSocial(String razonSocial) {
    this.razonSocial = razonSocial;
}

public String getDireccion() {
    return direccion;
}

public void setDireccion(String direccion) {
    this.direccion = direccion;
}

public int getEstado() {
    return estado;
}

public void setEstado(int estado) {
    this.estado = estado;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

@Override
public int describeContents() {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
    dest.writeInt(this.tipo);
    dest.writeInt(this.estado);
    dest.writeLong(this.id);
    dest.writeString(this.razonSocial);
    dest.writeString(this.direccion);
    dest.writeString(this.contacto);
    dest.writeString(this.telefono);
    dest.writeString(this.detalle);

}

public Reparacion(Parcel in) {
    readFromParcel(in);
}

private void readFromParcel(Parcel in) {
    this.tipo = in.readInt();
    this.estado = in.readInt();
    this.id = in.readInt();
    this.razonSocial = in.readString();
    this.direccion = in.readString();
    this.contacto = in.readString();
    this.telefono = in.readString();
    this.detalle = in.readString();

}

public static final Parcelable.Creator<Reparacion> CREATOR = new Parcelable.Creator<Reparacion>() {
    public Reparacion createFromParcel(Parcel in) {
        return new Reparacion(in);
    }

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

public void almacenar(Context contexto){
    ReparacionBBDD rbd=new ReparacionBBDD(contexto);
    rbd.insert(this);
}

public void eliminar(Context contexto){
    ReparacionBBDD rbd=new ReparacionBBDD(contexto);
    rbd.delete(this);
}

public void actualizar(Context contexto){
    ReparacionBBDD rbd=new ReparacionBBDD(contexto);
    rbd.update(this);
}

}

The problem is that I can recovery the int data, but the string data is null when I received the object. how is it possible???

I have read a lot of codes, and I have do it a lot of times, but I don't know the mistake!!

very thanks!!!

user3235831
  • 45
  • 11

1 Answers1

4

You must retrieve data as the way (data-type & order) you added. So this line can cause the issue:

dest.writeLong(this.id);

Replace that with:

dest.writeInt(this.id);
semsamot
  • 805
  • 9
  • 11