[英]Call Java method from JSNI
I want to call Java method test()
from JSNI variable successHandler()
. 我想从JSNI变量successHandler()
调用Java方法test()
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. 你的test()
不是静态的。 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
") (此错误是GWT版本的“ 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 你可以在gwtproject.org找到一个真正好的教程
One more tip. 还有一个提示。 If you create javascript Callbacks within the JSNI, wrap them with en $entry()-function: 如果你在JSNI中创建javascript回调,请用en $ entry() - 函数包装它们:
$doc.purchaseAction(token,$entry( successHandler ), $entry( failureHandler));
This will enable the GWT uncaughtExceptionHandler 这将启用GWT uncaughtExceptionHandler
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.