Forums Register Login

Serialization

+Pie Number of slices to send: Send
Hi Guy's !!!
Wanted to pass formatted text in a Chat Appl.

Have created the following files :

import java.text.*;
import java.io.*;
public class FlashAttributedString extends AttributedString implements Serializable
{
public FlashAttributedString(String text)
{
super(text);
}
}


This class extends the class AttributedString and implements the Serializable interface.This class is then used in the following code :


import java.io.*;
public class SerializationDemo
{
public static void main(String args[])
{
try
{
FlashAttributedString obj = new FlashAttributedString("This is Seriaized");
System.out.println("obj = " + obj);
FileOutputStream fos = new FileOutputStream("serial.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(obj);
oos.flush();
oos.close();
}
catch(Exception e)
{
e.printStackTrace();
}

try
{
FlashAttributedString obj1;
FileInputStream fis = new FileInputStream("serial.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
obj1=(FlashAttributedString)ois.readObject();
ois.close();
System.out.println("obj1 = " + obj1);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}


On executing this file an exception was thrown at the line ois.readObject();
.

The Exception thrown was:

java.io.InvalidClassException:java.text.AttributedString;<init>
How should it be rectified ? Pls Suggest.
Thanks Guy's .
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 806 times.
Similar Threads
Serialization in K&B
why no any exception
Can you help me to tell the output of this program and how we are getting this....
Can't Understand How It Comes In Deserialization
compiler error saying method of serializable to be overridden
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 05:28:51.