1

我正在学习http://www.tutorialspoint.com/gwt/gwt_style_with_css.htm上的初学者教程。HelloWorld.html 文件的代码是:

<html>
<head>
<title>Hello World</title>
   <link rel="stylesheet" href="HelloWorld.css"/>
   <script language="javascript" src="helloworld/helloworld.nocache.js">
   </script>
</head>
<body>

<div id="mytext"><h1>Hello, World!</h1></div>
<div id="gwtGreenButton"></div>
<div id="gwtRedButton"></div>

</body>
</html>

在 HelloWorld.java(扩展入口点)中,我有:

RootPanel.get("gwtGreenButton").add(Btn1);
RootPanel.get("gwtRedButton").add(Btn2);

2 行: RootPanel.get() 总是导致 null。我不知道发生了什么,要检查什么?(太糟糕了,该网站没有评论/讨论部分)

谢谢。

4

1 回答 1

0

文档说

RootPanel.get(java.lang.String id)

获取与给定浏览器元素关联的根面板。

DOM.getElementById(java.lang.String)

获取与整个文档中给定唯一 ID 关联的元素。

尝试

com.google.gwt.user.client.DOM.getElementById("gwtGreenButton");

com.google.gwt.user.client.DOM.getElementById("gwtRedButton");
于 2013-04-21T13:28:28.153 回答