当我尝试编译我的GWT应用程序时,我收到很多错误。其中一些是
[ERROR] com.google.gwt.xml.client.impl.AttrImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.CDATASectionImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.CommentImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.DocumentFragmentImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.DocumentImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.ElementImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.EntityReferenceImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.NamedNodeMapImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.NodeImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.NodeListImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.ProcessingInstructionImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] com.google.gwt.xml.client.impl.TextImpl is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[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.
[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.
[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.
[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.
[ERROR] java.util.Collections.UnmodifiableRandomAccessList<T> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] java.util.Collections.UnmodifiableRandomAccessList<T> is not default instantiable (it must have a zero-argument constructor or no constructors at all) and has no custom serializer.
[ERROR] java.util.LinkedList.Node<E> is not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' or 'java.io.Serializable' nor does it have a custom field serializer
[ERROR] java.util.LinkedList.Node<E> has no available instantiable subtypes.
[ERROR] subtype java.util.LinkedList.Node<E> is not assignable to 'com.google.gwt.user.client.rpc.IsSerializable' or 'java.io.Serializable' nor does it have a custom field serializer
我的客户端代码中出现此错误!从我从互联网上读到的任何东西,它说我根本无法模拟在JRE容器中运行到GWT的所有标准方法,因为它将在运行时编译为Javascript。但我太缺乏经验,无法理解这个错误。非常感谢任何帮助!
答案 0 :(得分:1)
三个格言:
Can anything be serialized as long as it implements Serializable?
在java SE / EE字节码世界中,序列化更简单。在以下类声明中:
class Spider
implements Serializable{
String a;
Integer b;
Cobweb c;
}
编译器会在a和b中航行,因为String已经拥有自己的序列化编解码器(即编码器/解码器或编组器/解码器)。整数也是如此。
编译器然后通过提供自己的编解码器或Cobweb包含Serializable成员(例如
)来尝试查看Cobweb是否实现Serializableclass Cobweb
implements Serializable{
Boolean d;
Double e;
}
d和e都已经拥有序列化编解码器,这是由Sun / Oracle管理Java语言提供的。
如果CobWeb允许通用参数怎么办?
class Cobweb <T>
implements Serializable{
Boolean d;
T e;
}
Cobweb<Float>
是可序列化的,因为Java已经有一个Float的序列化编解码器。
但是,除非Donkey有自定义序列化编解码器,否则编译器会在以下
中出现错误class Spider
implements Serializable{
String a;
Integer b;
Cobweb<Donkey> c;
}
GWT可连续性意味着什么?
是不是足够实现Serializable?为什么Google会实施新的Serializable接口?不。这是谷歌的错,但不是谷歌的错。
GWT UI Java总是在运行之前编译为Javascript。 GWT UI Java的本机代码是Javascript而不是二进制Java字节码。显而易见的原因是浏览器只运行Javascript但不运行Java字节码。
在大多数情况下,实现Serializable会使您的类GWT可序列化。 GWT可序列化意味着存在GWT生成的Javascript代码,以便在需要时执行编解码器。即,编解码器是Java源代码而不是Java字节代码。编解码器必须可以翻译为Javascript,因为GWT序列化/反序列化在浏览器上运行。
但是,有许多类,GWT已经没有编解码器。例如,GregorianCalender和大多数需要反射的类。 GregorianCalender实现了Serializable,但GWT编译器在Java源代码中没有任何编解码器可以转换为Javascript。
GWT生成的Javascript无法运行时反射。因此,GWT通过对您可以使用的所有可能代码的预编译排列执行延迟绑定来补偿该缺陷。我相信GregorianCalendar会执行一些反射测量,并且为GregorianCalendar写一个GWT编解码器会使Javascript代码的排列数量过多。我相信这也是导致许多课程缺少编解码器的原因。有人请指正。
回到原来的问题 ....
java.util.LinkedList.Node<E>
所以,为了善良,世界上的E是什么?您是否用GWT序列化替换了E?
来自堆栈跟踪的证据(如果我甚至擅长跟踪堆栈跟踪)表明您甚至没有费心用实际类型替换泛型参数。通过这样做,您迫使GWT编译器将E视为类Object。并且没有人知道如何序列化Object类。你会像创世记41章中的法老告诉约瑟夫,
“约瑟夫请解释我的梦想,但我已经忘记了我的梦想,所以你必须告诉我我的梦想。”
答案 1 :(得分:0)
如第一行堆栈所示,要序列化,类需要具有没有参数的构造函数或具有自定义序列化程序。 java-custom-serialization这里是关于编写序列化器的主题