0

Just for testing I tried to use the Window.alert() function from the com.google.gwt.user.client.Window package in my playn project. But when I try to run the programm I got an Error Message like this:

"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. "

I really do not understand it. In my playn project is only client side code in use. So what's the problem?

Rock Solid
  • 91
  • 1
  • 4

1 Answers1

0

GWT.create() is currently supported in pure java in gwt trunk. I am using it in a playn project myself {albeit with a slight glitch: Force GWT compiler to stop pruning invalid CompilationUnits }.

If you download and build trunk, you will be able to circumvent GWT.create() issues by registering ClassInstantiators for whatever class is causing your errors. In this case, the Window class has a static instance of WindowImpl that is throwing this error when jvm hits the Window class. If you register a ClassInstantiator for WindowImpl, this will not happen. Unfortunately, the Window.alert method goes straight to native js, so it may still bomb out on you.

If you don't know how / want to build gwt from trunk, ping me an email and I can send you the jars. If you still have problems with .alert() being a native method, let me know, and I will create a custom trunk build that defers .alert() into the WindowImpl singleton, so you can have it do something meaningful, like popup an alert message ;-}

If you feel adventurous, download gwt trunk, go into Window, copy the static alert method into an instance-level method on WindowImpl, make the original method delegate to WindowImpl, and then in your java code, call ServerGwtBridge.register(WindowImpl.class, new ClassInstantiator(){...}), and return whatever implementation you want for .alert() in java and android.

Community
  • 1
  • 1
Ajax
  • 2,465
  • 23
  • 20
  • Of course, it would probably be easier to just register a delegate service that is different for each build, and have gwt call Window.alert() while java or android popup a widget. You would then have to run your calls to alert through the delegate, but it saves you the trouble of hacking against trunk. – Ajax May 31 '12 at 16:04