4 Replies Latest reply: May 13, 2010 6:06 AM by 794822 RSS

    How to detect which part of my class cannot be serialized ?

    794822
      I want to serialize a class and a receive the error :

      java.io.NotSerializableException: geocost.Wio
      +     at java.io.ObjectOutputStream.writeObject0(Unknown Source)+
      +     at java.io.ObjectOutputStream.writeObject(Unknown Source)+
      +     at geocost.Wutiles.Wversion(Wutiles.java:229)+ this is the line number where I write the object (that has been correctly created)
      +     at geocost.Weditor$2.actionPerformed(Weditor.java:241)+
      +     at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)+
      +     at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)+
      +     at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)+
      +     at javax.swing.DefaultButtonModel.setPressed(Unknown Source)+
      +     at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)+
      +     at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)+
      +     at java.awt.Component.processMouseEvent(Unknown Source)+
      +     at javax.swing.JComponent.processMouseEvent(Unknown Source)+
      +     at java.awt.Component.processEvent(Unknown Source)+
      +     at java.awt.Container.processEvent(Unknown Source)+
      +     at java.awt.Component.dispatchEventImpl(Unknown Source)+
      +     at java.awt.Container.dispatchEventImpl(Unknown Source)+
      +     at java.awt.Component.dispatchEvent(Unknown Source)+
      +     at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)+
      +     at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)+
      +     at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)+
      +     at java.awt.Container.dispatchEventImpl(Unknown Source)+
      +     at java.awt.Window.dispatchEventImpl(Unknown Source)+
      +     at java.awt.Component.dispatchEvent(Unknown Source)+
      +     at java.awt.EventQueue.dispatchEvent(Unknown Source)+
      +     at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)+
      +     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)+
      +     at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)+
      +     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)+
      +     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)+
      +     at java.awt.EventDispatchThread.run(Unknown Source)+
      java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: geocost.Wio
      and more ....

      Sincerely, I dont know where to look to find a element cannot be serialized ...
      Is there a debug option (or another trik) to see where the write fails ?
      Thanks
        • 1. Re: How to detect which part of my class cannot be serialized ?
          EJP
          java.io.NotSerializableException: geocost.Wio
          ...
          at geocost.Wutiles.Wversion(Wutiles.java:229) this is the line number where I write the object (that has been correctly created)
          Sincerely, I dont know where to look to find a element cannot be serialized ...
          You have got to be kidding. The exception has told you which class isn't serializable, and the stack trace has told you where it is called from, and it has also told you how many levels of writeObject() have been called, i.e. two, one for the actual object you are writing and one for its non-serializable member.
          • 2. Re: How to detect which part of my class cannot be serialized ?
            794822
            That is : I symply cannot serialize this class , isnt it ?
            But I wish to know wich elements cannot be serialized, must i to look into all javadoc links to know what is not serializable ?
            Is there a tool to check a whole class to know this ?
            Thanks
            • 3. Re: How to detect which part of my class cannot be serialized ?
              EJP
              It's not 'elements', it's the entire class. The class that the exception said is not serializable. It is not serializable. Check its Javadoc. Or its source code. If you want to serialize it, make it implement Serializable. If you can't do that, review whether you really want to serialize it, i.e. whether it makes any sense to try to do so. Often it doesn't, and often that's the reason why classes aren't made Serializable. And if you don't want to serialize it, make the class member(s) that refer to it transient.
              • 4. Re: How to detect which part of my class cannot be serialized ?
                794822
                Ok ! Thanks
                Sometimes one tends to look into the tripes of a problem when the solution is outside and clear.
                (It is as a printer does not work and you check the drivers, the OS, etc and ..... it was not plugged in .... )
                Thanks again