我很难尝试序列化我的课程(从字面上看3-4小时才能找到解决方案)。我一个子类添加到现有的序列化和功能类,并比收到以下错误信息:GWT +系列化
[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
我班的样子:
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;
}
.
.
.
}
当我评论了“私人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;
}
而不是试图用这个作为我的功能类,它是好吧......但这件事真的让我心烦......
有什么想法吗? Gwt不支持子类序列化?或者我想念一些东西。赞扬任何答案。
最好的问候, 彼得
这就是@jusio所说的:内部非静态类需要一个封闭实例,所以它们的构造函数会收到一个额外的参数(编译时)。这就是为什么它抱怨没有零参数构造函数。在这种情况下,我认为最合适的是将LogCollection声明为“公共静态类”,以使其与封闭类型无关。或者直接将其移至自己的新文件。删除'private LogCollection ...'字段的原因是GWT意识到它不需要子类型并忽略它。 – helios 2012-02-09 14:09:06
是真的,但它看起来也是比较成功,但如果我写“实现可序列化”的GWT不再抱怨了,所以静态和实现也是不可抱怨的。奇怪是不是? – czupe 2012-02-09 14:32:57