2012-02-09 7 views
2

私はクラスをシリアル化しようとしています(文字通り3-4時間)。私は、既存の直列化可能と機能クラスにサブクラスを追加し、次のエラーメッセージを取得より:私は「プライベートLogCollection logColl」行をコメントするとGWT +シリアライズ

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; 
    } 
. 
. 
. 
} 

[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 

私のクラスは、のように見えますOKですが、コメントを外すとエラーメッセージが表示されます。それは、

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; 

} 

そして、私の機能クラスとしてこれを使用しようとするよりも:あなたは私がすべてのサブクラス変数コメントが、私は新しいクラスを作成する場合...とにかく役立つことはできません見るように私は、静的なキーワードで試してみましたOK ...しかし、このことは本当に私の心を悩ましています...

何か考えますか?サブクラスのシリアル化をサポートしていませんか?それとも、私は何かが恋しいです。すべての答えを確認してください。

よろしく、 ピーター

+1

これは@jusioの言うことです:内部ではない静的なクラスは囲むインスタンスを必要とするので、コンストラクタは(コンパイル時に)追加の引数を受け取ります。だから、それはゼロ引数のコンストラクタを持たないことについて不平を言っているのです。この場合、LogCollectionを「パブリック静的クラス」として宣言して、囲むタイプと無関係にすることが最も適切です。または、それを直接新しいファイルに移動することもできます。 'private LogCollection ...'フィールドを削除するのは、GWTがサブタイプを必要としないことを認識して無視するからです。 – helios

+0

真実ですが、それはまたcompailingしているようですが、 "Serializableを実装する" GWTはもう文句を言っていないので、静的で実装しても不平を言うことは不可欠です。奇妙じゃない? – czupe

答えて

7

このエラー:

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

はそれがデフォルトで作成しLogCollectionのインスタンスではないことを言います。それは本当です。 LogCollectionのインスタンスを作成するためには、まずItemRecRpcというインスタンスが必要です。静的なクラスとしてLogCollectionを宣言すれば助けになったはずです。

基本的に、gwt-rpcでオブジェクトを送信する場合、そのオブジェクトのフィールドとして使用されるすべてのクラスは、デフォルトでインスタンス化可能である必要があります。 (例えば、それを作成するための特別なトリックはなく、新しい空のコンストラクタのみ)。また、任意のクラスに対してカスタムフィールドシリアライザを定義することができます。これらはデフォルトでインスタンス化できます。

+0

完璧な回答、ありがとう。それは私の問題を解決しました。 (静的に試してみましたが、それほど多くのプロジェクトがあって、適切なものを構築していませんでした:/ facepalm :(しかし今、あなたが教えてくれたように、私は集中して適切なプロジェクトを再構築して、それはいいです!) – czupe

+0

ok testing、it、and lastコメントは失敗しました:(まだ同じメッセージがありますが、本当に奇妙です.GWTの問題があるかもしれません...そして、あなたはどのクラスでもサブクラスを作ることはできません...私はこのバグを乗り越えようとしています... 「パブリック静的クラスLogCollection」 – czupe

+0

[OK]を多分それは解決策を持っています。 「パブリック静的クラスLogCollectionはSerializableを実装」 は静的である必要がありますが、Seriazable aswellを実装する必要があるだけでなく...本当に奇妙なことでこれは、SerializableクラスのサブクラスがSerializable(明示的に追加することなく)を実装していますが、 GWTは私が見ているように...本当に不思議です...しかし、これは静的であり、キーワードを実装しているのでエラーメッセージはありません。 – czupe