Mathew
Mathew

Reputation: 670

GWT problem with calling Java methods from JSNI

I tried the example from google at this page: http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=DevGuideJavaFromJavaScript

I want to be able to call a Java method from JSNI, but nothing happens. No errors but the methods are not called. However, I can modify the fields from my class.

Here is the code I tried:

package com.jsni.client;
import com.google.gwt.core.client.EntryPoint;

public class Testjsnii implements EntryPoint {
      String myInstanceField;
      static int myStaticField;

      void instanceFoo(String s) {
          System.out.println(s);
      }

      static void staticFoo(String s) {
          System.out.println(s);
      }

      public native void bar(Testjsnii x, String s) /*-{

        this.@com.jsni.client.Testjsnii::instanceFoo(Ljava/lang/String;)(s);
        x.@com.jsni.client.Testjsnii::instanceFoo(Ljava/lang/String;)(s);
        @com.jsni.client.Testjsnii::staticFoo(Ljava/lang/String;)(s);
        var val = this.@com.jsni.client.Testjsnii::myInstanceField;
      }-*/;

    public void onModuleLoad() {
        bar(this,"Hello");
    }
}

It prints nothing on the console but only a waring that says:

[WARN] [testjsnii] - JSNI method '@com.jsni.client.Testjsnii::bar(Lcom/jsni/client/Testjsnii;Ljava/lang/String;)' returned > a value of type JavaScript object(1) but was declared void; it should not have returned a > value at all

I wonder what is the problem.

Thanks for the help.

Upvotes: 3

Views: 3312

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64561

You're actually running into a Chrome (10-dev) issue with the GWT DevMode plugin: http://code.google.com/p/google-web-toolkit/issues/detail?id=5778

Upvotes: 3

Related Questions