我正在試圖爲以下字段的類實現parcelable。當我嘗試從字段String(String mStyle []和byte [] mImage)中創建包(放入包中)的類時,我得到一個異常。我在writeToParcel的這些字段上沒有收到任何錯誤 - 什麼是正確的用法?。感謝很多如何使用String []和byte []字段爲類實現Parcelable?
private String mClothingItemName;
private String mColor;
private String mPrint;
private String mStyle[];
private String mMaterial;
private String mBrand;
private String mStorageLocation;
private String mOptionalDescription;
private byte[] mImage;
public void writeToParcel(Parcel out, int flags) {
out.writeString(mClothingItemName);
out.writeLong(mClothesId);
out.writeString(mColor);
out.writeString(mPrint);
//out.writeStringArray(mStyle);
out.writeString(mMaterial);
out.writeString(mBrand);
out.writeString(mStorageLocation);
out.writeString(mOptionalDescription);
// out.writeByteArray(mImage);
}
private Clothes(Parcel in) {
mClothingItemName = in.readString();
mClothesId = in.readLong();
mColor = in.readString();
mPrint = in.readString();
// in.readStringArray(mStyle);
mMaterial = in.readString();
mBrand = in.readString();
mStorageLocation = in.readString();
mOptionalDescription = in.readString();
//in.readByteArray(mImage);
}
你會得到哪些例外? –
@ Goopal rao --- 02-07 06:41:51.653:E/AndroidRuntime(3150):引起:java.lang.NullPointerException 02-07 06:41:51.653:E/AndroidRuntime(3150):\t at android.os.Parcel.readStringArray(Parcel.java:931) 02-07 06:41:51.653:E/AndroidRuntime(3150):\t at abacus.dmbasys.closetorganizer.Clothes。(Clothes.java:323) –
user3013499