Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Serialization

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
What kind of corn soldier are you? And don't say "kernel" - that's only for this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic