Serialization ...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Saturday, September 8, 2001 06:22 AM

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[]) { t   More>>

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;

How should it be rectified ? Pls Suggest.

Thanks Guy's .

   <<Less

Re: Serialization ...

Posted By:   John_Zukowski  
Posted On:   Saturday, September 8, 2001 09:08 PM

If I had to guess, the runtime is based on 1.1 and thus the java.text.AttributedString class isn't there.


Actually... I'm looking at the class docs for AttributedString and that class isn't marked as Serializable. Just because you mark a subclass as serializable, doesn't automatically make the parent serializable.

About | Sitemap | Contact