android getint,android - Unmarshalling unknown type code XXXXX at offset YYY when using getIntent()....

I'm trying to pass an int value from activity A to activity B.

Activity A:

Intent intent = new Intent(ActivityA.this, ActivityB.class);

intent.putExtra("list_size", list.size());

for (int i = 0; i < list.size(); i++) {

intent.putExtra("account" + i, accountList.get(i));

}

startActivityForResult(intent, 2);

Activity B:

private void init() {

Intent intent = getIntent();

int listSize = intent.getIntExtra("list_size", 0); // Error thrown here

for (int i = 0; i < listSize; i++) {

newList.add((Account) intent.getParcelableExtra("account" + i));

}

}

Account (this is the list item):

public class Account implements Parcelable {

private Long accountId;

private String accountName;

private Set followedAccountsIds = new HashSet<>();

private Set followersAccountsIds = new HashSet<>();

private Set likedTagsIds = new HashSet<>();

private Set postsByAccount = new HashSet<>();

public Account() {

}

public Account(Long accountId, String accountName, Set followedAccountsIds,

Set followersAccountsIds, Set likedTagsIds, Set postsByAccount) {

this.accountId = accountId;

this.accountName = accountName;

this.followedAccountsIds = followedAccountsIds;

this.followersAccountsIds = followersAccountsIds;

this.likedTagsIds = likedTagsIds;

this.postsByAccount = postsByAccount;

}

// Omitted getters and setters for brevity

protected Account(Parcel in) {

if (in.readByte() == 0) {

accountId = null;

} else {

accountId = in.readLong();

}

accountName = in.readString();

}

public static final Creator CREATOR = new Creator() {

@Override

public Account createFromParcel(Parcel in) {

return new Account(in);

}

@Override

public Account[] newArray(int size) {

return new Account[size];

}

};

@Override

public int describeContents() {

return 0;

}

@Override

public void writeToParcel(Parcel parcel, int i) {

parcel.writeLong(accountId);

parcel.writeString(accountName);

}

}

Error that is thrown:

Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@8b4252e: Unmarshalling unknown type code 6357091 at offset 140

at android.os.Parcel.readValue(Parcel.java:2453)

at android.os.Parcel.readArrayMapInternal(Parcel.java:2727)

at android.os.BaseBundle.unparcel(BaseBundle.java:269)

at android.os.BaseBundle.getInt(BaseBundle.java:867)

at android.content.Intent.getIntExtra(Intent.java:6637)

at com.david.songshareandroid.activities.ActivityB.init(ActivityB.java:33)

at com.david.songshareandroid.activities.ActivityB.onCreate(ActivityB.java:28)

at android.app.Activity.performCreate(Activity.java:6912)

at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2877)

In ActivityB when intent.getIntExtra("list_size", 0) is invoked, the error above occurs. If I remove the for loop in ActivityA, that is the objects are not getting passed to ActivityB, then the error does not occur anymore.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值