我正在尝试使用Kryo序列化一些对象的列表(一个自定义的类: List> )。
list2D; // List<List<MyClass>> which is already produced.
Kryo k1 = new Kryo();
Output output = new Output(new FileOutputStream("filename.ser"));
k1.writeObject(output, (List<List<Myclass>>) list2D);
output.close();到目前为止没有问题,它写出的列表没有错误。但当我试着读它的时候:
Kryo k2 = new Kryo();
Input listRead = new Input(new FileInputStream("filename.ser"));
List<List<Myclass>> my2DList = (List<List<Myclass>>) k2.readObject(listRead, List.class);我得到了这个错误:
Exception in thread "main" com.esotericsoftware.kryo.KryoException: Class cannot be created (missing no-arg constructor): java.util.List我该如何解决这个问题?
发布于 2014-02-16 18:32:27
在读回对象时不能使用List.class,因为List是一个接口。
k2.readObject(listRead, ArrayList.class);发布于 2013-01-22 20:23:19
根据您的错误,您可能希望将无参数构造函数添加到您的类中:
public class MyClass {
public MyClass() { // no-arg constructor
}
//Rest of your class..
}https://stackoverflow.com/questions/14458382
复制相似问题