CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: It did not look as problem

  1. #1
    Join Date
    Mar 2010
    Posts
    74

    It did not look as problem

    Simple standard serialization example, i am trying serializa to file and deserialize object f class Data
    public class Serial {

    class Data implements java.io.Serializable{
    Data () {param = 1; str = "TEST TEST TEST";};
    Data (int _param) {param =_param;};
    public String str;
    public int param;
    }

    public
    Serial() throws ClassNotFoundException{
    Object object = new Data();//new javax.swing.JButton("push me");
    ObjectOutputStream out = null;
    try {

    Stack stack = new Stack();

    stack.push(object);
    stack.push(object);
    stack.push(object);

    out = new ObjectOutputStream(new FileOutputStream("F://htmls//filename.ser"));

    out.writeObject(stack);
    out.close();

    ObjectInputStream inStream = new ObjectInputStream(new FileInputStream("F://htmls//filename.ser"));
    Stack content = (Stack) inStream.readObject();
    System.out.println("size: "+content.size());
    inStream.close();
    } catch (IOException ex) {
    Logger.getLogger(Serial.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
    try {
    out.close();
    } catch (IOException ex) {
    Logger.getLogger(Serial.class.getName()).log(Level.SEVERE, null, ex);
    }
    }

    }
    }

    I got exception below, on out.writeObject(stack); File filename.ser is not empty, looking like as serialized object( at least, I am able find test string "TEST TEST TEST"; there.
    What is wrong? why occurs java.io.NotSerializableException, nothing prevents class Data to be serialized..


    25 бер 2011 17:49:47 javaapplication10.Serial <init>
    SEVERE: null
    java.io.NotSerializableException: javaapplication10.Serial
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)

    .........................
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
    at javaapplication10.Serial.<init>(Serial.java:47)
    at javaapplication10.ThreadSerial.main(ThreadSerial.java:128)

  2. #2
    Join Date
    Mar 2011
    Location
    Dunwoody GA
    Posts
    8

    Re: It did not look as problem

    The exception is being thrown because your Serial class does not implement java.io.Serializable.
    Ray

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)