GWT&x2B;系列化

GWT&x2B;系列化,gwt,serialization,subclass,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

我很难尝试序列化我的类(实际上需要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 
[ERROR]com.google.gwt.user.client.ui.DelegatingChangeListenerCollection不是默认的instantiable(它必须有零参数构造函数或根本没有构造函数),并且没有自定义序列化程序。(通过com.client.rpc.ItemRecRpc访问)
[错误]com.google.gwt.user.client.ui.DelegatingClickListenerCollection不是默认的instantiable(它必须有零参数构造函数或根本没有构造函数),并且没有自定义序列化程序。(通过com.client.rpc.ItemRecRpc访问)
[错误]com.google.gwt.user.client.ui.DelegatingFocusListenerCollection不是默认的instantiable(它必须有零参数构造函数或根本没有构造函数),并且没有自定义序列化程序。(通过com.client.rpc.ItemRecRpc访问)
[错误]com.google.gwt.user.client.ui.DelegatingKeyboardListenerCollection不是默认的instantiable(它必须有零参数构造函数或根本没有构造函数),并且没有自定义序列化程序。(通过com.client.rpc.ItemRecRpc访问)
[错误]com.google.gwt.view.client.ListDataProvider.ListWrapper不是默认的instantiable(它必须有零参数构造函数或根本没有构造函数),并且没有自定义序列化程序。(通过com.client.rpc.ItemRecRpc访问)
[错误]com.client.rpc.ItemRecRpc.LogCollection不是默认的instantiable(它必须具有零参数构造函数或根本没有构造函数),并且没有自定义序列化程序。(通过com.client.rpc.ItemRecRpc访问)
[错误]com.client.rpc.ItemRecRpc.LogCollection没有可用的可实例化子类型。(通过com.client.rpc.ItemRecRpc访问)
[错误]子类型com.client.rpc.ItemRecRpc.LogCollection不是默认可实例化的(它必须具有零参数构造函数或根本没有构造函数),并且没有自定义序列化程序。(通过com.client.rpc.ItemRecRpc访问)
[错误]java.util.AbstractList.SubList不是默认的instantiable(它必须有零参数构造函数或根本没有构造函数),并且没有自定义序列化程序。(通过com.client.rpc.ItemRecRpc访问)
[错误]java.util.Collections.UnmodifiableList不是默认的instantiable(它必须有零参数构造函数或根本没有构造函数),并且没有自定义序列化程序。(通过com.client.rpc.ItemRecRpc访问)
[错误]java.util.Collections.UnmodifiableRandomAccessList不是默认的instantiable(它必须具有零参数)
我的班级看起来像:

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;
    }
.
.
.
}
public类ItemRecRpc实现可序列化{
私有静态最终长serialVersionUID=-582810889065152661L;
.
.
私有字符串rId;
private LogCollection logColl;//如果我对此进行注释,则不会显示错误消息。。。
公共类日志集合{
公众日志收集(){
}
//public long creationTime=System.currentTimeMillis();
//公共LongVector时间=新LongVector();
//public ArrayList messages=new ArrayList();
//公共int nSkipped=0;
//公共整数nExceptions=0;
//公共异常firstException=null;
//公共long-endGcTime=0;
公共长期服务;
}
.
.
.
}
当我注释“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;

}
公共类LogCollectionRpc实现可序列化{
公共LogCollectionRpc(){
//
}
public long creationTime=System.currentTimeMillis();
公共LongVector时间=新LongVector();
public ArrayList messages=new ArrayList();
public int nSkipped=0;//由于达到限制
public int nExceptions=0;//由于MyAppender-s
公共异常firstException=null;//由于MyAppender-s
公共long-endGcTime=0;
公共长期服务;
}
而不是试着用它作为我的函数类,它是好的…但这件事真的困扰着我的头脑

有什么想法吗?Gwt不支持子类序列化?或者我错过了什么。请给出答案

致以最良好的祝愿, Peter

此错误:

子类型com.client.rpc.ItemRecRpc.LogCollection不是默认可实例化的

默认情况下,它不能创建
LogCollection
的实例。这是真的。因为要创建
LogCollection
的实例,首先需要有一个
itemrecpc
的实例。将
LogCollection
声明为静态类应该会有所帮助


基本上,当您希望通过gwt rpc发送某个对象时,默认情况下,该对象中用作字段的所有类都应该是可实例化的(例如,没有创建它的特殊技巧,只有新的空构造函数)。您还可以为任何类定义自定义字段序列化程序,默认情况下可以实例化。

回答得很好,谢谢。这解决了我的问题。(我尝试了静态,但有太多的项目,没有构建合适的项目:/facepalm:(但现在正如您所说,我集中精力,重新构建合适的项目,这很好!)测试失败:(仍然有同样的信息,真的很奇怪,也许这是一个严重的GWT问题…你不能让任何类中的子类实现seriazable…我正在努力克服这个错误…“公共静态类LogCollection”好的。也许它有一个解决方案:“公共静态类LogCollection implements Serializable”不仅需要是静态的,而且还需要实现Serializable…其中真正奇怪的是,据我所知,Serializable类的子类也实现了Serializable(无需添加显式),但在GWT中我看不到…真的吗