本文介绍了从JSNI调用Java方法的GWT问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本页尝试了谷歌的例子:



我希望能够从JSNI调用Java方法,但什么都没发生。没有错误,但方法没有被调用。但是,我可以修改我的类中的字段。



以下是我尝试的代码:

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

公共类Testjsnii实现EntryPoint {
字符串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 /郎/字符串;)(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);




$ b $ p
$ b

它不会在控制台上打印任何内容,说:

lockquote
[testjsnii] - JSNI方法
'@ com.jsni.client.Testjsnii :: bar( Lcom / jsni / client / Testjsnii; Ljava / lang / String;)'returned>一个类型为JavaScript对象(1)的值,但被声明为void;它应该不会返回一个值>

我想知道问题所在。



感谢您的帮助。

解决方案

您实际上遇到Chrome(10-dev)问题, GWT DevMode插件:

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:

I wonder what is the problem.

Thanks for the help.

解决方案

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

这篇关于从JSNI调用Java方法的GWT问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 09:10