• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Doubt on Serialization?

 
Ranch Hand
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My program is compiles but throws the following exception at runtime:-
java.io.NotActiveException: not in call to writeObject
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:413)
at Test.writeObject(Test.java:10)
at Test.main(Test.java:23)

please explain me why it throws NotActiveException,I am confused....



[ August 10, 2008: Message edited by: Ashok Pradhan ]

[ August 10, 2008: Message edited by: Ashok Pradhan ]
[ August 10, 2008: Message edited by: Ashok Pradhan ]
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The javadocs of the defaultWriteObject method explain why you're getting this exception - you're not serializing the current object.

I think what you may mean to call is "os.writeObject(new Test())". Then you need to implement the writeObject method as explained in the javadocs for Serializable.
 
Ashok Pradhan
Ranch Hand
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my program the class Dog does not implements Serializable interface:-




but I want manually write doglegs by serialization as well as all the members of Test class(e.g Cat c=new Cat()) :-



but how can I invoke the writeObject() it throws NotActiveException and what are the changes needed to fulfill my program's requirement.
 
author
Posts: 23919
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

but how can I invoke the writeObject() it throws NotActiveException and what are the changes needed to fulfill my program's requirement.



Basically, you are *not* supposed to call the writeObject() method directly. It is a method used to support Serialization. See Ulf explanation on how to serialize an object. The serialization will indirectly call the writeObject() method.

Henry
 
Ashok Pradhan
Ranch Hand
Posts: 180
Netbeans IDE Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I got it.invoking readObject(ObjectOutputStream os) directly is the wrong process and it is automatically called in the serialization process.am I correct !!!.and my program now compiles and run successfully..



Thanks Ulf Dittmer and Henry !!!
[ August 10, 2008: Message edited by: Ashok Pradhan ]
 
expectation is the root of all heartache - shakespeare. tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic