Serialization 在java中打开序列化对象时出现InvalidClassException
好的,我有一个类Region的对象,我想保存它。我已经使Region和Region类中的所有类实现了可序列化。我的保存方法工作得非常好,但当我尝试使用以下方法打开保存的文件时:Serialization 在java中打开序列化对象时出现InvalidClassException,serialization,Serialization,好的,我有一个类Region的对象,我想保存它。我已经使Region和Region类中的所有类实现了可序列化。我的保存方法工作得非常好,但当我尝试使用以下方法打开保存的文件时: // ---------------------------------------------------------- /** * Open a Region object with the given fileName. * * @param fileName * @return The desired R
// ----------------------------------------------------------
/**
* Open a Region object with the given fileName.
*
* @param fileName
* @return The desired Region object.
*/
public static Region openRegion(String fileName)
{
try
{
FileInputStream fis = new FileInputStream(fileName + ".txt");
ObjectInputStream ois = new ObjectInputStream(fis);
Object readObject = ois.readObject();
ois.close();
if (readObject != null && readObject instanceof Region)
{
return (Region)readObject;
}
}
catch (IOException e)
{
e.printStackTrace();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
return null;
}
但是我得到了以下错误:java.io.InvalidClassException:htm.model.Cell;没有有效的构造函数
位于java.io.ObjectStreamClass$ExceptionInfo.newInvalidClassException(未知源)
位于java.io.ObjectStreamClass.checkDeserialize(未知源)
Cell对象是Region对象中的一个类,但它定义了一个构造函数,其工作方式如下:
公共单元格(列,int-columnIndex)
{
超级(列,列索引);
this.predictionSteps=0;
this.predictingState=false;
this.previousPredictionState=false;
this.learningState=false;
this.previousLearningState=false;
this.listOfDistalSegments=新的ArrayList(5);
}
很抱歉问了这么长的问题,但我不知道我做错了什么。谢谢 最近的不可序列化的单元格基类必须有一个公共的无参数构造函数