English 中文(简体)
拯救尚未序列化物体如回收物体的神秘等级
原标题:Saving my Serialized Class that have not serialized objects like Rect

当活动叫Destroy()但试图用目标OutputStream a java.io.NotSerializable书写我的物体时,我试图挽救我的宇宙物体。 tion灭了。

请帮助我。 增 编

问题回答

我也遇到了同样的问题,使这一类别有助于序列化:

public class SerializableRect implements Serializable {

private static final long serialVersionUID = 1L;

private Rect mRect;

public SerializableRect(Rect rect) {
    mRect = rect;
}

public Rect getRect() {
    return mRect;
}

private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    int left = mRect.left;
    int top = mRect.top;
    int right = mRect.right;
    int bottom = mRect.bottom;

    out.writeInt(left);
    out.writeInt(top);
    out.writeInt(right);
    out.writeInt(bottom);
}

private void readObject(java.io.ObjectInputStream in) throws IOException,
        ClassNotFoundException {
    int left = in.readInt();
    int top = in.readInt();
    int right = in.readInt();
    int bottom = in.readInt();

    mRect = new Rect(left, top, right, bottom);
}
}

如果您的物体图含有一个不可测的物体,则该仪器会找不到一个论点构造者,以便提出带有违约值的物体并移入。 它可以放弃这一例外。 底线是,每一物体在贵国物体图表中注明,必须:

  1. Implements Serializable, (and all of it s members do too), or
  2. Inherits from a base class that implements Serializable(and all members follow the rules), or
  3. Implements Serializable and all unserializable members are marked as Volatile, or
  4. Unserializable members not so marked have a no-argument default constructor for use in deserialization.

你没有为我提供更多细节,但我可以不向你们写这封信? 总的来说,你可以来自不可扩展的班级,也可以总结这些班级,并提供必要的功能。 只要每个成员符合我所列条件,就不应提出例外。

你们需要确保这一类别实施<代码>java.io.Serializable接口。 还考虑使用Bundles,并在onSaveInstanceState上保存你的数据。 关于数据储存的更多信息,见rel=“nofollow”>。





相关问题
Choosing the right subclass to instantiate programmatically

Ok, the context is some serialization / deserialization code that will parse a byte stream into an object representation that s easier to work with (and vice-versa). Here s a simplified example ...

WCF Problem Sending Object To Client

Background Converting from using .Net Remoting to WCF. Most of the methods on the WCF server are working fine, but ran into one that isn t working today. This is the service contract: [...

WCF DataMember Serializing questions

Ok, so I was part way through the long winded process of creating DTOs for sending my model over the wire and I don t feel like I m going down the right route. My issue is that most of the entities ...

deserialize the XML Document --- Need Help

I am using the below code snippet now to deserialize the XML document ... [WebMethod] public XmlDocument OrderDocument(XmlDocument xmlDoc) { XmlSerializer serializer = new XmlSerializer(typeof(...

How do I serialize a child class?

how do I include the serialized data from a child class where both impliment iserializeable? Class A Implements ISerializable dim _B as new B Class B Implements ISerializable ...

WCF: Serialize complex objects with read-only members

Looking for some guidance on a WCF service I’m prototyping. I have a WCF service hosted in IIS that will pass data to my clients. I have a separate shared assembly that contains all my business ...

Long/multiple SQL queries vs Serialization

I m trying to improve the performance of my web app where a page does a long query to pull data from different tables on a database. It pulls invoice data with multiple item lines, invoice status, and ...

热门标签