Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Serialization  RSS feed

 
Savio Mascarenhas
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!