【问题标题】:Deferred binding failed GWT using uibinder使用 uibinder 延迟绑定失败的 GWT
【发布时间】:2013-02-26 10:23:25
【问题描述】:

以下是项目中使用的文件总数。它给出了这些错误

[ERROR] [cricketscore] - Deferred binding failed for 'test.client.UserDashboard.MyUiBinder'; expect subsequent failures

[ERROR] [cricketscore] - Unable to load module entry point class test.client.DashBoard (see associated exception for details). 

请帮我解决其中的问题。

Cricketscore.gwt.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  When updating your version of GWT, you should also update this DTD reference,
  so that your app can take advantage of the latest GWT module capabilities.
-->
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.0//EN"
  "http://google-web-toolkit.googlecode.com/svn/tags/2.5.0/distro-source/core/src/gwt-module.dtd">
<module rename-to='cricketscore'>
  <!-- Inherit the core Web Toolkit stuff.                        -->
  <inherits name='com.google.gwt.user.User'/>

  <!-- Inherit the default GWT style sheet.  You can change       -->
  <!-- the theme of your GWT application by uncommenting          -->
  <!-- any one of the following lines.                            -->
  <inherits name='com.google.gwt.user.theme.clean.Clean'/>
  <!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
  <!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
  <!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/>     -->

  <!-- Other module inherits                                      -->

  <!-- Specify the app entry point class.                         -->
  <entry-point class='test.client.DashBoard'/>

  <!-- Specify the paths for translatable code                    -->
  <source path='client'/>
  <source path='shared'/>

</module>

仪表板.java

package test.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

public class DashBoard implements EntryPoint{

    @Override
    public void onModuleLoad() {
        RootPanel.get().add(new UserDashboard());
    }
}   

UserDashboard.ui.xml

<!-- UserDashboard.ui.xml -->

<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
    xmlns:g='urn:import:com.google.gwt.user.client.ui'
    xmlns:my='urn:import:test.client' >

  <g:HTMLPanel>
    <my:CricketScores ui:field='scores' teamNames='AUS, SAF, WA, QLD, VIC'/>
  </g:HTMLPanel>
</ui:UiBinder>

CricketScores.java

package test.client;

import com.google.gwt.uibinder.client.UiConstructor;
import com.google.gwt.user.client.ui.Composite;


public class CricketScores extends Composite{

    public @UiConstructor CricketScores(String teamNames) {
          this(teamNames.split("[, ]+"));
        }

    public CricketScores(String... teamNames) {
        // TODO Auto-generated constructor stub
    }
}

UserDashboard.java

package test.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiFactory;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;

public class UserDashboard extends Composite {
      interface MyUiBinder extends UiBinder<Widget, UserDashboard>{}
      private static final MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

      private final String[] teamNames;

      public UserDashboard(String... teamNames) {
        this.teamNames = teamNames;
        initWidget(uiBinder.createAndBindUi(this));
      }

      @UiFactory CricketScores makeCricketScores() { 
        return new CricketScores(teamNames);
      }
    }

【问题讨论】:

  • 而“...关联异常...”在哪里?
  • 异常是 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl 的 java.lang.reflect.InvocationTargetException .invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:406) at com。 com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:5 上的 google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
  • 这是整个异常吗?尝试在构造函数中注释掉this(teamNames.split("[, ]+"));
  • 请运行编译(而不是 DevMode)以获得更好的例外情况,并使用 full 日志更新您的问题。
  • 重新绑定 test.client.UserDashboard.MyUiBinder 调用生成器 com.google.gwt.uibinder.rebind.UiBinderGenerator [错误] CricketScores 类没有合适的 setTeamNames() 方法: (:8) [ERROR] 'test/client/UserDashboard.java' 中的错误 [ERROR] 第 13 行:无法解析 'test.client.UserDashboard .MyUiBinder' 通过延迟绑定 [WARN] 对于以下类型,生成的源从未提交(您是否忘记调用 commit()?) [WARN] test.client.UserDashboard_MyUiBinderImpl

标签: gwt web uibinder toolkit deferred


【解决方案1】:

您的代码中有冲突信息:@UiConstructor@UiFactory(实际上并不冲突,有优先顺序,但它可能会让开发人员(即您)感到困惑) .

UiBinder 将更喜欢 @UiFactory 而不是 @UiConstructor,并且您的工厂没有参数,因此 XML 中的 teamNames 属性暂时映射到不存在的 setTeamNames 设置器,因此“类 CricketScores 没有适当的 setTeamNames() 方法” 错误。

问题是您的代码中的概念性问题:您的 UserDashboard 是使用传递给 CricketScores 小部件的团队名称列表构造的,因此该小部件不应在 XML 中具有 teamNames 属性。

【讨论】:

  • thanx man .... 你知道除了 google-developers 网站之外的任何 uifactory 和 uiconstructor 网站.... 他们对这些概念的给出非常有限
【解决方案2】:

我遇到了同样的错误,并且 uiField(provided=true) 得到了 null,但是当我在构造函数中创建相应组件的对象时它得到了解决

【讨论】:

    猜你喜欢
    • 2013-08-09
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    • 2012-05-12
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    相关资源
    最近更新 更多