can somebody xplain how to use the externalizable interface to write my own serialization. i would appreciate an example that demonstrates writing and reading of an object which implements the Externalizable interface. thanx in advance...
"Component Development for the Java Platform" by Stuart Dabbs Halloway (chapter4) has an excellent treatment on serialization (in particular, there are good explanations of potential problems with externalizable You can download the book here.
the foll code which i used to try Externalizable interface throws an eception as below on execution
the exception is
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
I haven't really looked at your code or tried to figure out the problem, but one potential source of confusion/bugs is your exception handling strategy in the writeExternal and readExternal methods. If an exception were thrown during the execution of either method, nobody would ever know about it - they just bury the exception and return. I'd at least print a message to the error output stream, System.err .
Thrown when the Serialization runtime detects one of the following problems with a Class... The class does not have an accessible no-arg constructor.
Does your class have an accessible no-arg constructor? Not if the client trying to access it is not in the same package. Getting any ideas?
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
Your code seems to compile and run as expected when the aforementioned mistake is corrected.
Bijesh Krishnadas
Ranch Hand
Joined: Aug 08, 2002
Posts: 31
posted
0
thanx dirk. it helped. so it actually is cos whatever class is trying to create the object of my test class is in the default jdk package! But any ideas as to how the instantiation is actually done. i.e. which class handles it. thanx
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
posted
0
I recommend that you take a look at the documentation and the source code.