vis*_*050 -1 java serialization
我有这门课
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];
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用下面给出的一段代码将类的实例写入磁盘时
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 );
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
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)
Run Code Online (Sandbox Code Playgroud)
我们非常欢迎任何帮助.
编辑:我已经检查过HashMap已经实现了serializable.