使用serializable传递我的对象时出错?

时间:2013-10-28 03:45:42

标签: java android class exception serializable

我试图将我的对象类GastronomyElement发送到另一个活动,但我有这个错误

java.lang.RuntimeException: Parcelable   encountered IOException writing serializable    object (name =    com.example.despegarteproject.classes.GastronomyElement)

我见过这样的其他帖子,但我无法解决。这是我的班级代码

 public class GastronomyElement implements Serializable {

    String id, name, formattedAddress, formattedPhoneNumber,  reference, photo;
    List<String> photos;
    Boolean openNow;
    Horarios horarios;
    List<Review> reviews;
    String priceLevel;
    double  latitude, longitude;
    Double rating;

    public String getName () {
        return name;
    }

    public void setName (String name) {
        this.name = name;
    }

    public String getId () {
        return id;
    }

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

    public String getFormattedAddress () {
        return formattedAddress;
    }

    public void setFormattedAddress (String formattedAddress) {
        this.formattedAddress = formattedAddress;
    }

    public String getReference () {
        return reference;
    }

    public void setReference (String reference) {
        this.reference = reference;
    }

    public String getPhoto () {
        return photo;
    }

    public void setPhoto (String photo) {
        this.photo = photo;
    }

    public List<String> getPhotos () {
        return photos;
    }

    public void setPhotos (List<String> photos) {
        this.photos = photos;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude (double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude (double longitude) {
        this.longitude = longitude;
    }

    public Double getRating () {
        return rating;
    }

    public void setRating (Double rating) {
        this.rating = rating;
    }

    public Boolean getOpenNow () {
        return openNow;
    }

    public void setOpenNow (Boolean openNow) {
        this.openNow = openNow;
    }

    public Horarios getHorarios () {
        return horarios;
    }

    public void setHorarios (Horarios horarios) {
        this.horarios = horarios;
    }

    public String getPriceLevel () {
        return priceLevel;
    }

    public void setPriceLevel (String priceLevel) {
        this.priceLevel = priceLevel;
    }

    public String getFormattedPhoneNumber () {
        return formattedPhoneNumber;
    }

    public void setFormattedPhoneNumber (String formattedPhoneNumber) {
        this.formattedPhoneNumber = formattedPhoneNumber;
    }

    public List<Review> getReviews () {
        return reviews;
    }

    public void setReviews (List<Review> reviews) {
        this.reviews = reviews;
    }

    }

这就是我发送它的方式

Intent act = new Intent (context, ActivityLugarDetalles.class);
act.putExtra("elementDetails", elementDetails);
startActivity(act);

我将非常感谢你的帮助!谢谢!

1 个答案:

答案 0 :(得分:4)

由于GastronomyElement包含HorariosReview类型的对象,因此这些类(以及它们包含的任何字段,递归)也必须实现Serializable。异常可能是因为其中一个类(或其中一个类中包含的某些数据)无法实现Serializable。 (GastronomyElement的其他字段都已实现Serializable。)