RuntimeException: Parcel android.os.Parcel: Unmarshalling unknown type code when using android bundle

蓝咒 提交于 2019-12-13 14:22:14

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/37651708/runtimeexception-parcel-android-os-parcel-unmarshalling-unknown-type-code-when

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!