如何为具有String []和byte []字段的类实现Parcelable?

时间:2014-02-07 10:46:59

标签: android

我正在尝试为具有以下字段的类实现parcelable。尝试从字段String mStyle []和byte [] mImage中的parcel(放入一个包)创建类时我得到一个例外。我没有在writeToParcel上的这些字段上收到任何错误 - 什么是正确的用法?。非常感谢

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

    } 

1 个答案:

答案 0 :(得分:1)

我建议您使用网站link,从一个类中生成代码以使其变得可分。