序列化包含位图的类

时间:2014-08-06 04:40:49

标签: android object serialization bitmap

我有一个自定义类,如下所示

公共类GeneralObject实现Serializable {

private static final long serialVersionUID = 1L;
private String caption;
private String imageName;
private String postid;
private Bitmap bitmap;

//setters
public void setImage(String imageName){
    this.imageName = imageName;
}

public void setCaption(String caption){
    this.caption = caption;
}

public void setPostId(String postid){
    this.postid = postid;
}

public void setBitmap(Bitmap bitmap) {
    this.bitmap = bitmap;
}

//getters
public String getCaption(){
    return caption;
}

public String getImage(){
    return imageName;
}

public Bitmap getBitmap() {
    return bitmap;
}

public String getPostId(){
    return postid;
}

}

我正在尝试使用以下代码将其序列化

public final class SerializeTest {

private SerializeTest(){}

public static void writeObject(Context context, String key, Object object) throws IOException {
    FileOutputStream fos = context.openFileOutput(key, Context.MODE_PRIVATE);
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(object);
    oos.close();
    fos.close();
}

public static Object readObject(Context context, String key) throws IOException, ClassNotFoundException {
    FileInputStream fis = context.openFileInput(key);
    ObjectInputStream ois = new ObjectInputStream(fis);
    Object object = ois.readObject();
    return object;
}

}

但是我得到了异常" java.io.notserializableexception android.graphics.bitmap"。我知道这是因为我在对象中有一个位图。有人可以建议我解决这个问题吗?我的意思是一种序列化位图和对象数据的方法?非常感谢示例代码。

提前致谢

0 个答案:

没有答案