为什么无法使用GWT UI Binder模板从我的项目中使用ClientBundle

时间:2012-06-19 11:07:48

标签: gwt

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
    xmlns:g='urn:import:com.google.gwt.user.client.ui'>

    <ui:with field='res' type='com.myproject.resources.Resources'/>

    <ui:style>
        .panel {
            background-color: ivory;
        }
    </ui:style>

    <g:FlowPanel styleName='{style.panel}'>
        <g:Image url='{res.logo}'/>
        <g:VerticalPanel>
            <g:PushButton text="My Button" ui:field="myButton"></g:PushButton>
        </g:VerticalPanel>
    </g:FlowPanel>
</ui:UiBinder>

我有一个资源类

public interface  Resources extends ClientBundle {
      public static final Resources INSTANCE =  GWT.create(Resources.class);

      @Source("logo.png")
      ImageResource logo();


}

我在GWT XML编辑器中没有出现任何错误,但GWT设计器不会加载。当我运行它时,我也得到了一个例外。

onModuleLoad() threw an exception
Exception while loading module com.myproject.client.MyProject. See Development Mode for details.

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:396)
    at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: Deferred binding failed for 'com.myproject.client.ClientFactory' (did you forget to inherit a required module?)
    at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53)
    at com.google.gwt.core.client.GWT.create(GWT.java:97)
    at com.myproject.client.MyProject.onModuleLoad(MyProject.java:42)
    ... 9 more
Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
    at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:503)
    at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
    ... 11 more

2 个答案:

答案 0 :(得分:2)

很难说是否是你的问题,但你的代码应该是:

<g:Image resource='{res.logo}'/>

(即resource,而非url

答案 1 :(得分:1)

确保gwt.xml文件中有此继承标记,使用ClientBundle时需要它:

<inherits name="com.google.gwt.resources.Resources" />