czu*_*upe 2 gwt serialization subclass
我很难尝试序列化我的课程(实际上是3-4个小时才找到解决方案).我将一个子类添加到现有的可序列化和正常运行的类中,并获取以下错误消息:
[ERROR] com.google.gwt.user.client.ui.DelegatingChangeListenerCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
[ERROR] com.google.gwt.user.client.ui.DelegatingClickListenerCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
[ERROR] com.google.gwt.user.client.ui.DelegatingFocusListenerCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
[ERROR] com.google.gwt.user.client.ui.DelegatingKeyboardListenerCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
[ERROR] com.google.gwt.view.client.ListDataProvider<T>.ListWrapper<> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
[ERROR] com.client.rpc.ItemRecRpc.LogCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
[ERROR] com.client.rpc.ItemRecRpc.LogCollection has no available instantiable subtypes. (reached via com.client.rpc.ItemRecRpc)
[ERROR] subtype com.client.rpc.ItemRecRpc.LogCollection is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
[ERROR] java.util.AbstractList.SubList<E> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
[ERROR] java.util.Collections.UnmodifiableList<T> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer. (reached via com.client.rpc.ItemRecRpc)
[ERROR] java.util.Collections.UnmodifiableRandomAccessList<T> is not default instantiable (it must have a zero-argument
Run Code Online (Sandbox Code Playgroud)
我的班级看起来像:
public class ItemRecRpc implements Serializable {
private static final long serialVersionUID = -5828108890651522661L;
.
.
private String rId;
private LogCollection logColl;//if i comment this, no error message...
public class LogCollection{
public LogCollection(){
}
//public long creationTime = System.currentTimeMillis();
//public LongVector times = new LongVector();
//public ArrayList<Object> messages = new ArrayList<Object>();
//public int nSkipped = 0;
//public int nExceptions = 0;
//public Exception firstException = null;
//public long endGcTime=0;
public long endTime;
}
.
.
.
}
Run Code Online (Sandbox Code Playgroud)
当我评论"私有LogCollection logColl"行时,它没问题,但当我取消注释时我再次得到错误信息.我尝试使用static关键字,因为你看到我评论每个子类变量,但无法帮助...无论如何,如果我创建一个新类:
public class LogCollectionRpc implements Serializable {
public LogCollectionRpc() {
//
}
public long creationTime = System.currentTimeMillis();
public LongVector times = new LongVector();
public ArrayList<Object> messages = new ArrayList<Object>();
public int nSkipped = 0; // due to reaching the limit
public int nExceptions = 0; // due to MyAppender-s
public Exception firstException = null; // due to MyAppender-s
public long endGcTime = 0;
public long endTime;
}
Run Code Online (Sandbox Code Playgroud)
而不是尝试使用它作为我的功能类,它没关系...但这件事真的让我烦恼......
任何的想法?Gwt不支持子类序列化?或者我想念一些东西.感谢任何答案.
最诚挚的问候,彼得
这个错误:
subtype com.client.rpc.ItemRecRpc.LogCollection is not default instantiable
说它LogCollection默认不能创建和实例.这是事实.因为要创建一个实例LogCollection,首先需要有一个实例ItemRecRpc.声明LogCollection为静态类应该有所帮助.
基本上,当你想通过gwt-rpc发送一些对象时,默认情况下,所有用作此类对象中的字段的类都应该是可实例化的.(例如,没有特殊的技巧来创建它,只是新的和空的构造函数).您还可以为任何类定义自定义字段序列化程序,默认情况下可以对其进行实例化.