我很难尝试将我的类序列化(字面意思是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 我的类看起来像这样:
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;
}
.
.
.
}当我注释"private 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不支持子类序列化吗?还是我错过了什么。感谢你的回答。
致以最好的问候,彼得
发布于 2012-02-09 21:47:43
此错误:
subtype com.client.rpc.ItemRecRpc.LogCollection is not default instantiable
表示默认情况下不能创建LogCollection的实例。这是真的。因为要创建LogCollection的实例,首先需要有一个ItemRecRpc的实例。将LogCollection声明为静态类应该会有所帮助。
基本上,当您希望通过gwt-rpc发送某个对象时,在此类对象中用作字段的所有类在缺省情况下都应该是可实例化的。(例如,没有特殊的技巧来创建它,只有新的和空的构造函数)。您还可以为任何类定义自定义字段序列化程序,默认情况下可以实例化这些序列化程序。
https://stackoverflow.com/questions/9211246
复制相似问题