I have this class
public class wordObject implements java.io.Serializable
{
String wordName;
int occCount;
int count;
HashMap<Integer, Double> lineDict;
int[] mat;
public wordObject(String name,int num)
{
wordName = name;
occCount=1;
count = num;
lineDict=new HashMap<Integer,Double>(lineC);
mat = new int[lineC];
}
}
But when I try to write an instance of the class to the disk using a piece of code as given below
public static writeObj(WordObject obj)
FileOutputStream f_out = new FileOutputStream(loc);
// Write object with ObjectOutputStream
ObjectOutputStream obj_out = new ObjectOutputStream (f_out);
// Write object out to disk,obj is instance of wordObject
obj_out.writeObject ( obj );
I get this error
Exception in thread "main" java.io.NotSerializableException: searchTAemd
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
Any help will be most welcome.
EDIT: I have checked that HashMap already implements serializable.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…