java中包裹类型,RuntimeException:包裹android.os.Parcel:使用android捆绑包时解组未知类型代码...

I am getting the below error message:

java.lang.RuntimeException: Parcel android.os.Parcel@41141190: Unmarshalling unknown type code 7602286 at offset 16

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

at android.os.Parcel.readMapInternal(Parcel.java:2094)

at android.os.Bundle.unparcel(Bundle.java:223)

at android.os.Bundle.getFloat(Bundle.java:981)

I am sending an object as a message using WiFi direct. Hence I am converting the object into byte array while sending and reversing the conversion while receiving.

My object has two fields - one String and one android bundle. While sending I am populating the string field and putting a float value in the android bundle using a key.

I am able to retrieve the string value at the receiver's end. The error comes when I try to retrieve the float value present inside the bundle using getFloat method. What could be the reason for this?

解决方案

After spending lots of hour i found solution, that i made mistake in Parcelable class, i forgot to write and read one of the parameters, finally i solved issue, my code look like:

public void writeToParcel(Parcel dest, int flags) {

dest.writeString(filepath);

dest.writeString(filename);

dest.writeString(fileCount);

dest.writeInt(index);

}

public YourParcelableClassName(Parcel in){

filepath = in.readString();

filename = in.readString();

fileCount = in.readString();

index = in.readInt();

}

in the first activity pass data,

Intent mIntent = new Intent(YourFirstActivity.this,YourSecondActivity.class);

mIntent.putExtra("position",position);

mIntent.putParcelableArrayListExtra("filedata",parcelableArrayList);

startActivity(mIntent);

for getting intent data into second activity,

int Position = getIntent().getIntExtra("position",0);

parcelableArrayList = getIntent().getParcelableArrayListExtra("filedata");

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值