1
<?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
4

2 回答 2

2

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

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

(即resource,不是url

于 2012-06-19T12:42:18.417 回答
1

确保你的 gwt.xml 文件中有这个继承标签,使用 ClientBundle 时需要它:

<inherits name="com.google.gwt.resources.Resources" />
于 2012-06-19T13:29:55.237 回答