问题
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