我有以下代码:
public static void show(String value){
Window.alert("From Java");
invokeMethod(); //Does not get called
}
public static native void invokeMethod() /*-{
alert("From JSNI");
}-*/; 我想从Java方法中调用一个JSNI方法,但是invokeMethod()从来没有被调用过...我找不到很多从Java调用JSNI方法的用例。
为什么上面的代码不起作用?
发布于 2012-05-31 17:52:22
首先,正如Colin Alworth所说,您需要将代码更改为$wnd.alert("From JSNI");如果您想调用除alert()之外的另一个JS函数,则应该在html页面中编写函数体。您将找到所需的所有信息here
因此,您的代码应该如下所示:
public static void show(String value){
Window.alert("From Java");
invokeMethod();
}
public static native void invokeMethod() /*-{
$wnd.alert("From JSNI"); //Added "$wnd."
}-*/; https://stackoverflow.com/questions/10788413
复制相似问题