简体   繁体   English

JSNI Hello World无法正常工作

[英]JSNI Hello World is not working

I have done a simple Hello World GWT example using JSNI. 我已经使用JSNI完成了一个简单的Hello World GWT示例。 It does nothing but display a message. 它只显示一条消息,什么也不做。

This is the code in an EntryPoint class: 这是EntryPoint类中的代码:

public void onModuleLoad() {
  // TODO Auto-generated method stub
  alert("Hello World!");
 }
 native void alert(String msg) /*-{
  $wnd.alert(msg);
 }-*/;
}

I see this Exception: 我看到此异常:

java.lang.reflect.InvocationTargetException
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

Any idea why? 知道为什么吗?

I created the sample GWT project and copied your code into the entry point and it worked fine. 我创建了示例GWT项目,并将您的代码复制到了入口点,并且工作正常。 I think you have a deeper set up problem. 我认为您有一个更深层次的设置问题。 I would look over your *.gwt.xml file and make sure it isn't malformed and check your GWT library references etc. Also open up the Run Configration and make sure it is a Web Application. 我将查看您的* .gwt.xml文件,并确保它没有格式错误,并检查您的GWT库引用等。还要打开“运行配置”,并确保它是一个Web应用程序。

    /**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class So implements EntryPoint {


    native void alert(String msg) /*-{ 
      $wnd.alert(msg); 
     }-*/; 

    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {

        alert("Hello World!"); 
    }
}

你可能不运行在DevMode的这个代码,但在一个普通的JVM,其中GWT不能做它的魔力

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM