Results 1 to 9 of 9
  1. #1
    Sandia_man is offline Member
    Join Date
    May 2010
    Posts
    12
    Rep Power
    0

    Default Can I Serialize "this"??

    I'm doing a little application.

    I need to be able to open that application in other place and continue working with exactly the same "program".

    I though in serializing the main object, is this doable?? Because I've been trying but I couldn't make it...

    What would you recommend me?

    thanks!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    I've been trying but I couldn't make it.
    Can you show us what you've done and what your problems were?

  3. #3
    Sandia_man is offline Member
    Join Date
    May 2010
    Posts
    12
    Rep Power
    0

    Default

    this is what I have



    int val= fc.showOpenDialog(this);

    if (val == JFileChooser.APPROVE_OPTION) {
    file = fc.getSelectedFile();
    }

    try {
    FileOutputStream fos = new FileOutputStream(file);
    ObjectOutputStream out = new ObjectOutputStream(fos);

    out.writeObject(this);
    out.close();

    } catch (Exception e) {
    System.out.println("It failed!");
    }

    thanks!

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    What happens when you execute the code you've posted?
    Were there problems?

  5. #5
    Sandia_man is offline Member
    Join Date
    May 2010
    Posts
    12
    Rep Power
    0

    Default

    It fails in out.writeObject(this);

    The program prints the "It failed!"

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Add: e.printStackTrace();
    statement to the catch block to get the error message.
    Copy and paste that message here.

  7. #7
    Sandia_man is offline Member
    Join Date
    May 2010
    Posts
    12
    Rep Power
    0

    Default

    here it is!

    java.io.NotSerializableException: javax.swing.GroupLayout
    at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1156)
    at java.io.ObjectOutputStream.access$300(ObjectOutput Stream.java:143)
    at java.io.ObjectOutputStream$PutFieldImpl.writeField s(ObjectOutputStream.java:1668)
    at java.io.ObjectOutputStream.writeFields(ObjectOutpu tStream.java:454)
    at java.awt.Container.writeObject(Container.java:3548 )
    at sun.reflect.GeneratedMethodAccessor7.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at java.io.ObjectStreamClass.invokeWriteObject(Object StreamClass.java:945)
    at java.io.ObjectOutputStream.writeSerialData(ObjectO utputStream.java:1461)
    at java.io.ObjectOutputStream.writeOrdinaryObject(Obj ectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1150)
    at java.io.ObjectOutputStream.writeArray(ObjectOutput Stream.java:1338)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1146)
    at java.io.ObjectOutputStream.access$300(ObjectOutput Stream.java:143)
    at java.io.ObjectOutputStream$PutFieldImpl.writeField s(ObjectOutputStream.java:1668)
    at java.io.ObjectOutputStream.writeFields(ObjectOutpu tStream.java:454)
    at java.awt.Container.writeObject(Container.java:3548 )
    at sun.reflect.GeneratedMethodAccessor7.invoke(Unknow n Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at java.io.ObjectStreamClass.invokeWriteObject(Object StreamClass.java:945)
    at java.io.ObjectOutputStream.writeSerialData(ObjectO utputStream.java:1461)
    at java.io.ObjectOutputStream.writeOrdinaryObject(Obj ectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1150)
    at java.io.ObjectOutputStream.writeArray(ObjectOutput Stream.java:1338)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1146)
    at java.io.ObjectOutputStream.access$300(ObjectOutput Stream.java:143)
    at java.io.ObjectOutputStream$PutFieldImpl.writeField s(ObjectOutputStream.java:1668)
    at java.io.ObjectOutputStream.writeFields(ObjectOutpu tStream.java:454)
    at java.awt.Container.writeObject(Container.java:3548 )
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at java.io.ObjectStreamClass.invokeWriteObject(Object StreamClass.java:945)
    at java.io.ObjectOutputStream.writeSerialData(ObjectO utputStream.java:1461)
    at java.io.ObjectOutputStream.writeOrdinaryObject(Obj ectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1150)
    at java.io.ObjectOutputStream.writeArray(ObjectOutput Stream.java:1338)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1146)
    at java.io.ObjectOutputStream.access$300(ObjectOutput Stream.java:143)
    at java.io.ObjectOutputStream$PutFieldImpl.writeField s(ObjectOutputStream.java:1668)
    at java.io.ObjectOutputStream.writeFields(ObjectOutpu tStream.java:454)
    at java.awt.Container.writeObject(Container.java:3548 )
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at java.io.ObjectStreamClass.invokeWriteObject(Object StreamClass.java:945)
    at java.io.ObjectOutputStream.writeSerialData(ObjectO utputStream.java:1461)
    at java.io.ObjectOutputStream.writeOrdinaryObject(Obj ectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1150)
    at java.io.ObjectOutputStream.writeArray(ObjectOutput Stream.java:1338)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1146)
    at java.io.ObjectOutputStream.access$300(ObjectOutput Stream.java:143)
    at java.io.ObjectOutputStream$PutFieldImpl.writeField s(ObjectOutputStream.java:1668)
    at java.io.ObjectOutputStream.writeFields(ObjectOutpu tStream.java:454)
    at java.awt.Container.writeObject(Container.java:3548 )
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at java.io.ObjectStreamClass.invokeWriteObject(Object StreamClass.java:945)
    at java.io.ObjectOutputStream.writeSerialData(ObjectO utputStream.java:1461)
    at java.io.ObjectOutputStream.writeOrdinaryObject(Obj ectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1150)
    at java.io.ObjectOutputStream.writeArray(ObjectOutput Stream.java:1338)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1146)
    at java.io.ObjectOutputStream.access$300(ObjectOutput Stream.java:143)
    at java.io.ObjectOutputStream$PutFieldImpl.writeField s(ObjectOutputStream.java:1668)
    at java.io.ObjectOutputStream.writeFields(ObjectOutpu tStream.java:454)
    at java.awt.Container.writeObject(Container.java:3548 )
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at java.io.ObjectStreamClass.invokeWriteObject(Object StreamClass.java:945)
    at java.io.ObjectOutputStream.writeSerialData(ObjectO utputStream.java:1461)
    at java.io.ObjectOutputStream.writeOrdinaryObject(Obj ectOutputStream.java:1392)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutp utStream.java:1150)
    at java.io.ObjectOutputStream.writeObject(ObjectOutpu tStream.java:326)
    at Tablut.Juego.partidaBotonActionPerformed(Juego.jav a:717)
    at Tablut.Juego.access$800(Juego.java:29)
    at Tablut.Juego$9.actionPerformed(Juego.java:338)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387)
    at javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:242)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(BasicButtonListener.java:236)
    at java.awt.Component.processMouseEvent(Component.jav a:6263)
    at javax.swing.JComponent.processMouseEvent(JComponen t.java:3267)
    at java.awt.Component.processEvent(Component.java:602 8)
    at java.awt.Container.processEvent(Container.java:204 1)
    at java.awt.Component.dispatchEventImpl(Component.jav a:4630)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2099)
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:4574)
    at java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:4238)
    at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:4168)
    at java.awt.Container.dispatchEventImpl(Container.jav a:2085)
    at java.awt.Window.dispatchEventImpl(Window.java:2475 )
    at java.awt.Component.dispatchEvent(Component.java:44 60)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 599)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(E ventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:122)
    thanks for your help!!

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    Looks like you are using some classes that cause the: NotSerializableException: javax.swing.GroupLayout

  9. #9
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

Similar Threads

  1. Java, Military Format using "/" and "%" Operator!!
    By sk8rsam77 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 03:03 AM
  2. Replies: 1
    Last Post: 01-21-2010, 09:20 AM
  3. problem with argument list and precedence "(" and ")"
    By helpisontheway in forum Advanced Java
    Replies: 6
    Last Post: 12-24-2009, 07:50 AM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

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