• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 43081
77
  • 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: 23951
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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic