4

我想test()从 JSNI 变量中调用 Java 方法successHandler()。但是,我收到错误

[ERROR] - Line 110: Missing qualifier on instance method 'com.gw.myProject.client.presenter.payments.PaymentProgramPresenter.test'

原始代码:

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();
    }
4

1 回答 1

4

test()的不是静态的。因此,您需要将其设为静态或指定实例或将购买设为非静态。

(这个错误是“ Cannot make a static reference to the non-static method methodName() from the type TypeName”的GWT版本)

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();
}

你可以在gwtproject.org找到一个真正好的教程

还有一个提示。如果您在 JSNI 中创建 javascript 回调,请使用 en $entry()-function 包装它们:

$doc.purchaseAction(token,$entry( successHandler ), $entry( failureHandler));

这将启用 GWT uncaughtExceptionHandler

于 2013-11-11T20:18:11.527 回答