为什么无法从我的项目中获取 GWT UI 绑定器模板以使用客户端bundle


<?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
很难

判断是否是您的问题,但您的代码应该是:

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

(即 resource,不是url

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

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

最新更新