
Question:
I tried the example from google at this page: <a href="http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=DevGuideJavaFromJavaScript" rel="nofollow">http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=DevGuideJavaFromJavaScript</a>
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:
<blockquote>[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
</blockquote>I wonder what is the problem.
Thanks for the help.
Answer1:You're actually running into a Chrome (10-dev) issue with the GWT DevMode plugin: <a href="http://code.google.com/p/google-web-toolkit/issues/detail?id=5778" rel="nofollow">http://code.google.com/p/google-web-toolkit/issues/detail?id=5778</a>