One thing I tried was adding an 'export' method to the Foo class:
class Foo {
public Foo() {
this.export();
}
private native void export() /*-{
this.doBar = function() {this.@Foo::doBar()();}
}-*/;
public void doBar() {
// ... something
}
}
This causes, on creating an instance of Foo, the appropriate API
methods to be exposed in JavaScript. However, when running in hosted
mode, I get all kinds of Malformed JSNI Exceptions, whining about how
the 'doBar' field is not found.
[WARN] Malformed JSNI reference 'doBar'; expect subsequent failures
java.lang.NoSuchFieldError: doBar
at com.google.gwt.dev.shell.CompilingClassLoader
$DispatchClassInfoOracle.getDispId(CompilingClassLoader.java:122)
at com.google.gwt.dev.shell.CompilingClassLoader.getDispId
(CompilingClassLoader.java:574)
at com.google.gwt.dev.shell.mac.WebKitDispatchAdapter.setField
(WebKitDispatchAdapter.java:106)
at com.google.gwt.dev.shell.mac.LowLevelSaf.invokeImpl(Native Method)
at com.google.gwt.dev.shell.mac.LowLevelSaf.invoke(LowLevelSaf.java:
158)
at com.google.gwt.dev.shell.mac.ModuleSpaceSaf.doInvoke
(ModuleSpaceSaf.java:100)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:
453)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid
(ModuleSpace.java:251)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid
(JavaScriptHost.java:107)
at Foo.export(OAuthLogonService.java)
at Foo.<init>(OAuthLogonService.java:29)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:
105)
at com.google.gwt.dev.shell.mac.MethodDispatch.invoke
(MethodDispatch.java:71)
at org.eclipse.swt.internal.carbon.OS.SendEventToEventTarget(Native
Method)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2914)
at com.google.gwt.dev.SwtHostedModeBase.processEvents
(SwtHostedModeBase.java:235)
at com.google.gwt.dev.HostedModeBase.pumpEventLoop
(HostedModeBase.java:558)
at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)
This works no problem compiled in the browser, but it would be nice if
hosted mode would continue to work... As it is, it just bombs and
stops and doesn't go any further than the exception.