3

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) /*-{

        [email protected]::instanceFoo(Ljava/lang/String;)(s);
        [email protected]::instanceFoo(Ljava/lang/String;)(s);
        @com.jsni.client.Testjsnii::staticFoo(Ljava/lang/String;)(s);
        var val = [email protected]::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.

2
  • You might not see output to System.out - try using GWT.log() instead to see if the methods are being called. Commented Jan 5, 2011 at 21:35
  • 1
    I just copied your code straight across only modifying the package and System.out to logger.info() and it works perfectly fine, I don't even get the warning message you mentioned. Commented Jan 5, 2011 at 22:14

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

The bug is now fixed in Chrome 10.0.634 and higher.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.