gpt4 book ai didi

java - GWT JSNI - 如何使用 jsni 从 java 代码调用外部 javascript

转载 作者:行者123 更新时间:2023-12-01 12:47:03 26 4
gpt4 key购买 nike

我想在我的 gwt 应用程序中调用外部 javascript 函数

当我使用此代码时,它工作正常:我已经导入了javaScript,我可以在客户端的firebug中看到它

public static native void showOfflineMap(String pRegionId, String pMapServerHost, String pMapServerPath, String pMapTileLayers, String pFoiLayers,
double pMapCenterLon, double pMapCenterLat, int pInitZoom, String pNavPanel, boolean pCustJsFunction, int pMapWidth, int pMapHeight,
String pAdditional) /*-{
alert("ff");
$wnd.createPluginMap(
pRegionId,
pMapServerHost,
pMapServerPath,
pMapTileLayers,
pFoiLayers,
pMapCenterLon,
pMapCenterLat,
pInitZoom,
pNavPanel,
pCustJsFunction,
pMapWidth,
pMapHeight,
pAdditional
)


}-*/;

但是当我删除

alert("ff");

它抛出此异常:

Sun Jul 06 16:36:49 GMT+03:30 2014 com.google.gwt.logging.client.LogConfiguration
SEVERE: (TypeError) @ir.dena.avl.client.offlinemap.MapUtil::showOfflineMap(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;DDILjava/lang/String;ZIILjava/lang/String;)([string: 'offline_map', string: 'http://192.168.10.196:7001', string: '/mapviewer', string: 'mp.LINE_TILE', string: 'NONE', double: 56.0046, double: 32.629365, int: 3, string: 'WEST', bool: false, int: 1000, int: 800, string: 'OVER:MARQUEE:DISTANCE:REDLINE:FOISELECT']): $wnd.createPluginMap is not a functioncom.google.gwt.core.client.JavaScriptException: (TypeError) @ir.dena.avl.client.offlinemap.MapUtil::showOfflineMap(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;DDILjava/lang/String;ZIILjava/lang/String;)([string: 'offline_map', string: 'http://192.168.10.196:7001', string: '/mapviewer', string: 'mp.LINE_TILE', string: 'NONE', double: 56.0046, double: 32.629365, int: 3, string: 'WEST', bool: false, int: 1000, int: 800, string: 'OVER:MARQUEE:DISTANCE:REDLINE:FOISELECT']): $wnd.createPluginMap is not a function
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:304)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
at ir.dena.avl.client.offlinemap.MapUtil$.showOfflineMap(MapUtil.java)
at ir.dena.avl.client.offlinemap.OfflineMapView.createMainPanel(OfflineMapView.java:31)
at ir.jalal.core.client.view.BaseView.<init>(BaseView.java:71)
at ir.dena.avl.client.offlinemap.OfflineMapView.<init>(OfflineMapView.java:20)
at ir.dena.avl.client.ViewFactory$32.onSuccess(ViewFactory.java:354)
at com.google.gwt.core.client.GWT$1.execute(GWT.java:286)
at com.google.gwt.core.client.impl.SchedulerImpl$Task$.executeScheduled$(SchedulerImpl.java:50)
at com.google.gwt.core.client.impl.SchedulerImpl.runScheduledTasks(SchedulerImpl.java:180)
at com.google.gwt.core.client.impl.SchedulerImpl.flushPostEventPumpCommands(SchedulerImpl.java:345)
at com.google.gwt.core.client.impl.SchedulerImpl$Flusher.execute(SchedulerImpl.java:78)
at com.google.gwt.core.client.impl.SchedulerImpl.execute(SchedulerImpl.java:138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:284)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:356)
at sun.reflect.GeneratedMethodAccessor88.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Unknown Source)

请帮助我,

提前致谢

最佳答案

确保将脚本链接到 createPluginMap函数之前 .nocache.js并且不会异步链接它(我的意思是它应该没有 <script defer<script async )

关于java - GWT JSNI - 如何使用 jsni 从 java 代码调用外部 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24595724/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com