2014-09-02 66 views
1

我從antivity將對象發送給其他人。類是:Android Parcelable String null

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); 
} 

}

的問題是,我可以恢復int數據,但是當我收到該對象的字符串數據爲空。這怎麼可能???

我已經閱讀了很多代碼,我已經做了很多次,但我不知道這個錯誤!

非常感謝!!!

+0

我看到三個的readInt和兩個writeint和一個writelong。 – danny117 2014-09-02 18:13:02

回答

3

您必須按照添加的方式(數據類型&訂單)檢索數據。所以這條線可能會導致問題:

dest.writeLong(this.id); 

替換有:

dest.writeInt(this.id); 
+0

哦,我的天啊!這是這個!謝謝!! – user3235831 2014-09-09 14:56:09