从JSNI调用Java方法 [英] Call Java method from JSNI
问题描述
我想从JSNI变量 successHandler()
调用Java方法 test()
。但是,我得到错误
[错误] - 第110行:实例方法'com.gw.myProject.client缺少限定符。
$ b 原始码: $ b
public static native void(String token)/ * - {
var successHandler = function(status){//成功处理程序
return @ com.gw.myProject.client.presenter.payments.PaymentProgramPresenter :: test()();
}
var failureHandler = function(status){//失败处理程序
// $ wnd.alert('testing');
}
$ doc.purchaseAction(token,successHandler,failureHandler);
} - * /;
public void test(){
this.onHide();
解决方案 您的 test()
不是静态的。因此,您需要将其设置为静态或指定一个实例或使购买非静态。
(这个错误是GWT版本的不能从TypeName类型的非静态方法methodName() code $> $)
public native void purchase(String token)/ * - {
var instance = this;
var successHandler = function(status){// Success handler
return instance。@ com.gw.myProject.client.presenter.payments.PaymentProgramPresenter :: test()();
}
var failureHandler = function(status){//失败处理程序
// $ wnd.alert('testing');
}
$ doc.purchaseAction(token,successHandler,failureHandler);
} - * /;
public void test(){
this.onHide();
你可以在gproproject.org
还有一个提示。如果您在JSNI中创建了JavaScript回调函数,请使用en $ entry()函数进行包装:
$ doc.purchaseAction(token ,$ entry(successHandler),$ entry(failureHandler));
这将启用GWT uncaughtExceptionHandler
I want to call Java method test()
from JSNI variable successHandler()
. However, I get error
[ERROR] - Line 110: Missing qualifier on instance method 'com.gw.myProject.client.presenter.payments.PaymentProgramPresenter.test'
Original code:
public static native void purchase(String token) /*-{
var successHandler = function(status){ // Success handler
return @com.gw.myProject.client.presenter.payments.PaymentProgramPresenter::test()();
}
var failureHandler = function(status){ // Failure handler
// $wnd.alert('testing');
}
$doc.purchaseAction(token, successHandler, failureHandler);
}-*/;
public void test() {
this.onHide();
}
解决方案 Your test()
is not static. Therefore you will need to make it static or specify an instance or make the purchase non-static.
(This error is the GWT version of "Cannot make a static reference to the non-static method methodName() from the type TypeName
")
public native void purchase(String token) /*-{
var instance = this;
var successHandler = function(status){ // Success handler
return instance.@com.gw.myProject.client.presenter.payments.PaymentProgramPresenter::test()();
}
var failureHandler = function(status){ // Failure handler
// $wnd.alert('testing');
}
$doc.purchaseAction(token, successHandler, failureHandler);
}-*/;
public void test() {
this.onHide();
}
You can find a real good tutorial at gwtproject.org
One more tip. If you create javascript Callbacks within the JSNI, wrap them with en $entry()-function:
$doc.purchaseAction(token,$entry( successHandler ), $entry( failureHandler));
This will enable the GWT uncaughtExceptionHandler
这篇关于从JSNI调用Java方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文