首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GWT +序列化

GWT +序列化
EN

Stack Overflow用户
提问于 2012-02-09 20:57:12
回答 1查看 7.3K关注 0票数 2

我很难尝试将我的类序列化(字面意思是3-4小时才能找到解决方案)。我将一个子类添加到现有的可序列化且正常运行的类中,然后得到以下错误消息:

代码语言:javascript
复制
 [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 

我的类看起来像这样:

代码语言:javascript
复制
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关键字,正如你所见,我注释了每个子类变量,但没有帮助……无论如何,如果我创建了一个新类:

代码语言:javascript
复制
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不支持子类序列化吗?还是我错过了什么。感谢你的回答。

致以最好的问候,彼得

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-09 21:47:43

此错误:

subtype com.client.rpc.ItemRecRpc.LogCollection is not default instantiable

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

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

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9211246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档