我收到以下错误消息:
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)我使用WiFi直接将一个对象作为消息发送。因此,我在发送时将对象转换为字节数组,并在接收时反转转换。
我的对象有两个字段-一个字符串和一个android包。在发送时,我填充了字符串字段,并使用键将一个浮点值放入android包中。
我能够检索到接收方的字符串值。当我尝试使用getFloat方法检索包中存在的浮点值时,出现了错误。这可能是什么原因呢?
发布于 2017-02-23 18:37:09
在花了很长时间后,我找到了解决方案,我在Parcelable类中犯了错误,我忘记了写和读其中一个参数,最后我解决了这个问题,我的代码看起来像这样:
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();
}在第一个活动传递数据中,
Intent mIntent = new Intent(YourFirstActivity.this,YourSecondActivity.class);
mIntent.putExtra("position",position);
mIntent.putParcelableArrayListExtra("filedata",parcelableArrayList);
startActivity(mIntent);为了将意图数据放入第二个活动中,
int Position = getIntent().getIntExtra("position",0);
parcelableArrayList = getIntent().getParcelableArrayListExtra("filedata");https://stackoverflow.com/questions/37651708
复制相似问题