Android Int在可包裹后转换为不同的内容
我有一个这样的物体:Android Int在可包裹后转换为不同的内容,android,parcelable,Android,Parcelable,我有一个这样的物体: public class CommunityCurrencyContent implements Parcelable { private Double balance; private Long creationDate; private String description; private Double offerCount; private String communityIcon; private String co
public class CommunityCurrencyContent implements Parcelable {
private Double balance;
private Long creationDate;
private String description;
private Double offerCount;
private String communityIcon;
private String communityDescription;
private String communityName;
private String[] links;
private String code;
private Double memberCount;
private String communityImage;
private Integer pk;
public CommunityCurrencyContent(Parcel in) {
balance = in.readDouble();
creationDate = in.readLong();
description = in.readString();
offerCount = in.readDouble();
communityIcon = in.readString();
communityDescription = in.readString();
communityName = in.readString();
links = in.createStringArray();
code = in.readString();
memberCount = in.readDouble();
communityImage = in.readString();
pk = in.readInt();
}
public static final Creator<CommunityCurrencyContent> CREATOR = new Creator<CommunityCurrencyContent>() {
@Override
public CommunityCurrencyContent createFromParcel(Parcel in) {
return new CommunityCurrencyContent(in);
}
@Override
public CommunityCurrencyContent[] newArray(int size) {
return new CommunityCurrencyContent[size];
}
};
public Double getBalance() {
return balance;
}
public Long getCreationDate() {
return creationDate;
}
public String getDescription() {
return description;
}
public Double getOfferCount() {
return offerCount;
}
public String getCommunityIcon() {
return communityIcon;
}
public String getCommunityDescription() {
return communityDescription;
}
public String getCommunityName() {
return communityName;
}
public String[] getLinks() {
return links;
}
public String getCode() {
return code;
}
public Double getMemberCount() {
return memberCount;
}
public String getCommunityImage() {
return communityImage;
}
public Integer getPk() {
return pk;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeDouble(this.balance);
parcel.writeLong(this.creationDate);
parcel.writeString(this.description);
parcel.writeDouble(this.offerCount);
parcel.writeString(this.communityIcon);
parcel.writeString(this.communityDescription);
parcel.writeString(this.communityName);
parcel.writeString(this.code);
parcel.writeDouble(this.memberCount);
parcel.writeString(this.communityImage);
parcel.writeInt(this.pk);
}
}
公共类CommunityCurrencyContent实现可包裹{
私人双平衡;
私人长时间创作;
私有字符串描述;
私人双重报价;
私有字符串社区图标;
私有字符串社区描述;
私有字符串communityName;
私有字符串[]链接;
私有字符串码;
私人双重会员人数;
私有字符串社区映像;
私有整数pk;
公共社区货币内容(中的地块){
balance=in.readDouble();
creationDate=in.readLong();
description=in.readString();
offerCount=in.readDouble();
communityIcon=in.readString();
communityDescription=in.readString();
communityName=in.readString();
links=in.createStringArray();
code=in.readString();
memberCount=in.readDouble();
communityImage=in.readString();
pk=in.readInt();
}
公共静态最终创建者=新创建者(){
@凌驾
公共社区CurrencyContent createFromParcel(中的地块){
返回新的CommunityCurrencyContent(在中);
}
@凌驾
公共社区CurrencyContent[]新数组(整数大小){
返回新的CommunityCurrencyContent[大小];
}
};
公共双getBalance(){
收益余额;
}
公共长getCreationDate(){
还肌酐;
}
公共字符串getDescription(){
返回说明;
}
公共双getOfferCount(){
还盘金额;
}
公共字符串getCommunityIcon(){
返回社区图标;
}
公共字符串getCommunityDescription(){
返回社区描述;
}
公共字符串getCommunityName(){
返回社区名称;
}
公共字符串[]getLinks(){
返回链接;
}
公共字符串getCode(){
返回码;
}
公共双getMemberCount(){
返回成员计数;
}
公共字符串getCommunityImage(){
回归社区形象;
}
公共整数getPk(){
返回主键;
}
@凌驾
公共int描述内容(){
返回0;
}
@凌驾
公共无效书面包裹(包裹,内部i){
包裹。可减记(本。余额);
包裹的书写日期(本创建日期);
包裹书写(本说明);
可写包裹(本次报价金额);
parcel.writeString(此.communityIcon);
包裹书写(本社区描述);
包裹书写(本社区名称);
包裹书写(此代码);
parcel.writeDouble(this.memberCount);
parcel.writeString(此.communityImage);
包裹书写(此.pk);
}
}
在我通过意图传递这个对象之前,每个值都是正确的。在传递pk值后,一些字符串值会发生更改。例如,pk为5,通过后更改为3801203
有人能帮我吗,因为我看不出问题。您正在阅读链接的价值,但从未将其写入您的包裹:
links = in.createStringArray();
使用包裹时,您需要确保在读写时保持相同的顺序。您正在读取链接的值,但从未将其写入包裹:
links = in.createStringArray();
使用包裹时,您需要确保在阅读和书写时保持相同的顺序。我想我看到了一个轻微的错误;try
pk=(整数)pk.readValue(null)构造函数中的代码>。我怀疑与将int
自动装箱到Integer
有关,但我不确定是否有相反的操作-自动将Integer
转换为int
您阅读了链接,但没有编写它们?????有一个不匹配…哦,我错了,很可能是链接。我想我看到了一个轻微的错误;trypk=(整数)pk.readValue(null)构造函数中的代码>。我怀疑与将int
自动装箱到Integer
有关,但我不确定是否有相反的操作-自动将Integer
转换为int
您阅读了链接,但没有编写它们?????有一个不匹配…哦,我错了,很可能是链接。谢谢。我忽略了这个,谢谢。我忽略了这一点。