Reputation: 4919
I am having hard time trying to serialize my class (literally 3-4 hour to find a solutio). I add a subclass to an existing serializable and functioning class, and than get the following error message:
[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
My class looks like:
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;
}
.
.
.
}
When i comment the "private LogCollection logColl" line it is ok, but when i uncomment i again get the error mesage. I tried with static keyword, as you see i comment every subclass variable, but can not help... Anyway if i create a new class:
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;
}
And than try to use this as my functioning class, it is ok... But this thing is really bugging my mind...
Any idea? Gwt dont support subclass serialization? Or am i miss something. Aprreciate any answer.
Best Regards, Peter
Upvotes: 2
Views: 7386
Reputation: 9920
This error:
subtype com.client.rpc.ItemRecRpc.LogCollection is not default instantiable
Says that it can't create and instance of LogCollection
by default. And it is true. Because to create an instance of LogCollection
, you first need to have an instance of ItemRecRpc
. Declaring LogCollection
as static class should have helped.
Basically, when you want to send some object over gwt-rpc, all the classes used as fields in such object should be instantiable by default. (e.g. no special tricks to create it, just new and empty constructor). Also you can define a custom field serializer for any class, which can be instantiated by default.
Upvotes: 7