BrowserFunction不执行“JavaScript”代码

时间:2015-07-20 07:05:11

标签: javascript java browser

为什么BrowserFunction不执行我的Javascript代码?

Java代码:

public void createBrowserFunctions() {
    new BrowserFunction(mapView_Browser, "appi") {
        public Object function(Object[] arguments) {
            syncCenter((Double) arguments[0], (Double) arguments[1]);
            syncZoom((Double) arguments[2]);
            syncRotation((Double) arguments[3]);
            return null;
        }
    };
}

private void syncCenter(final Double latitude, final Double longitude) {
    LatLng newCenter = new LatLng(latitude.doubleValue(), longitude.doubleValue());
    CENTER = newCenter;
    fireCenterChanged();
}

private void syncZoom(final Double zoom) {
    int newZoom = zoom.intValue();

    if (newZoom != this.ZOOM) {
        this.ZOOM = newZoom;
        fireZoomChanged();
    }
}

private void syncCenter(final Double latitude, final Double longitude) {
    LatLng newCenter = new LatLng(latitude.doubleValue(), longitude.doubleValue());
    CENTER = newCenter;
    fireCenterChanged();
}

JavaScript代码:

 window._handleBoundsChanged = function() {
  if( !_blockEvents ) {
    appi( 10, 15, 20, 32 );
  }
};

执行时的控制台日志“_handleBoundsChanged();” :

osgi> !SESSION 2015-07-20 08:34:10.848 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.8.0_45
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=pl_PL
Command-line arguments:  -dev 

!ENTRY org.eclipse.rap.ui 4 0 2015-07-20 08:34:21.540
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.swt.SWTException: Failed to evaluate Javascript expression
  at org.eclipse.swt.browser.Browser.createException(Browser.java:606)
  at org.eclipse.swt.browser.Browser.evaluate(Browser.java:344)
  at hc.tool.mapviewer.rap.OLMap.setZoom(OLMap.java:67)
  at hc.tool.mapviewer.rap.View$1.widgetSelected(View.java:58)
  at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:262)
  at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
  at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:708)
  at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:610)
  at org.eclipse.swt.widgets.Display.executeNextEvent(Display.java:1216)
  at org.eclipse.swt.widgets.Display.runPendingMessages(Display.java:1197)
  at org.eclipse.swt.widgets.Display.safeReadAndDispatch(Display.java:1180)
  at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1172)
  at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2733)
  at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2694)
  at org.eclipse.ui.internal.Workbench.access$5(Workbench.java:2530)
  at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:701)
  at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:337)
  at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:684)
  at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:157)
  at hc.tool.mapviewer.rap.Application.start(Application.java:18)
  at org.eclipse.rap.ui.internal.application.EntryPointApplicationWrapper.createUI(EntryPointApplicationWrapper.java:38)
  at org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle.createUI(RWTLifeCycle.java:171)
  at org.eclipse.rap.rwt.internal.lifecycle.RWTLifeCycle$UIThreadController.run(RWTLifeCycle.java:283)
  at java.lang.Thread.run(Unknown Source)
  at org.eclipse.rap.rwt.internal.lifecycle.UIThread.run(UIThread.java:104)

我渴望将方法提供的数据从JavaScript提供给Java。 我指望你的帮助,谢谢。

1 个答案:

答案 0 :(得分:0)

因此,在Browser:344被调用后,评估在OLMap:67失败。你应该挖掘这两个点,看看发生了什么。

我准备打赌OLMap:67是你的function(Object []),而最终的原因是你试图投射Object(可能某种JSObject)到没有任何类型转换的java Double