The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

DJVCD (6) [Avatar] Offline
#1
I have a class which extends treeitem:
import com.google.gwt.user.client.ui.TreeItem;

public class TreeNode extends TreeItem
{
String id;
String parentId;
String type;
int idx;
String name;
String description;
String code;
// action is a reserved word
String operation;
String target;
Boolean enabled;

public TreeNode(String html)
{
super(html);
}


public String getId()
{
return id;
}

。。。。。。。
}

and write a custom field serializer:
public class TreeNode_CustomFieldSerializer
{
public static TreeNode instantiate(
SerializationStreamReader streamReader)
throws SerializationException
{
String html=streamReader.readString();
return new TreeNode(html);
}

public static void serialize(SerializationStreamWriter streamWriter,
TreeNode instance) throws SerializationException
{
streamWriter.writeString(instance.id);
....
}

public static void deserialize(SerializationStreamReader streamReader,
TreeNode instance) throws SerializationException
{
instance.id= streamReader.readString();
.....
}
}

and I want to transmit it between client and server,but got an exception:
----------------------------------------------------------------------------------
Caused by: java.lang.ExceptionInInitializerError: null
at com.tsolution.emc.client.gui.tree.TreeNode_CustomFieldSerializer.instantiate(TreeNode_CustomFieldSerializer.java:14)

the Line 14 is:
return new TreeNode(html);

What is this problem?How can I fix it?
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Detailed exception:


[WARN] StandardContext[]An IncompatibleRemoteServiceException was thrown while processing this call.
com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException: java.lang.reflect.InvocationTargetException
....
Caused by: com.google.gwt.user.client.rpc.SerializationException: java.lang.reflect.InvocationTargetException
....
Caused by: java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
.....
Caused by: java.lang.ExceptionInInitializerError: null
at com.tsolution.emc.client.gui.tree.TreeNode_CustomFieldSerializer.instantiate(TreeNode_CustomFieldSerializer.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
........
Caused by: java.lang.UnsupportedOperationException: ERROR: GWT.create() is only usable in client code! It cannot be called, for example, from server code. If you are running a unit test, check that your test case extends GWTTestCase and that GWT.create() is not called from within an initializer or constructor.
at com.google.gwt.core.client.GWT.create(GWT.java:91)
......
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
robert.hanson (173) [Avatar] Offline
#2
Re: Custom Field Serializer exception
Based on this error...

> ERROR: GWT.create() is only usable in client code!

It looks like you tried to use GWT.create() on the server. Realize that GWT.create() is only there to trigger code generation in the GWT compiler, you can't use it in your server code.
adam.tacy (269) [Avatar] Offline
#3
Re: Custom Field Serializer exception
> Based on this error...
>
> > ERROR: GWT.create() is only usable in client code!
>
> It looks like you tried to use GWT.create() on the
> server.

....just to add, you're probably getting caught because you're either directly or indirectly creating a UI component on the server and that UI component itself is calling GWT.create() (if you're not also doing it yourself!).

Looking quickly at TreeItem source code, it indeed calls GWT.create() at line 263.

You need to separate the model and view more, and should only send the data (model) across the interface and not the UI component (view).

//Adam