gpt4 book ai didi

java - 使用可序列化传递对象时出错?

转载 作者:行者123 更新时间:2023-12-01 18:41:56 25 4
gpt4 key购买 nike

我试图将我的对象类 GastronomyElement 发送到另一个 Activity ,但出现此错误

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

我看过类似的帖子,但我无法解决。这是我的类(class)代码

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

非常感谢您的帮助!谢谢!

最佳答案

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

关于java - 使用可序列化传递对象时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19626912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com