GWT-自定义小部件错误:无法读取未定义

时间:2016-03-24 10:19:46

标签: java gwt gwt-material-design

我对GWT很新。我想扩展一些标准小部件以满足我的需求。我创建了第一个小部件HorizontalTabs,它扩展了GWT MaterialDesign中的类(Here is demohere are sources)并且收到错误:Cannot read property 'hash' of undefined

以下是代码:

public class HorizontalTabs extends Composite {

    private static HorizontalTabsUiBinder uiBinder = GWT.create(HorizontalTabsUiBinder.class);

    interface HorizontalTabsUiBinder extends UiBinder<Widget, HorizontalTabs> {
    }
 public HorizontalTabs() {
    initWidget(uiBinder.createAndBindUi(this));
    }
}

<!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" xmlns:m="urn:import:gwt.material.design.client.ui">
    <m:MaterialRow>
        <m:MaterialRow>
            <m:MaterialColumn grid="s12">
                <m:MaterialTab ui:field="tab" backgroundColor="blue" indicatorColor="yellow" waves="YELLOW">

                </m:MaterialTab>
            </m:MaterialColumn>
        </m:MaterialRow>
        <m:MaterialRow ui:field="tabContentRow">

        </m:MaterialRow>
    </m:MaterialRow>
</ui:UiBinder> 

要使用它,我将其添加到我的一个视图类中,如下所示:

public class FilesView extends ViewWithUiHandlers<FilesUiHandlers> implements FilesPresenter.MyView {
    interface Binder extends UiBinder<Widget, FilesView> {}
    private static FilesViewUiBinder uiBinder = GWT.create(FilesViewUiBinder.class);
    interface FilesViewUiBinder extends UiBinder<Widget, FilesView> {}
    @UiField
    MaterialRow row;
    public FilesView() {
    initWidget(uiBinder.createAndBindUi(this));
    row.add(new HorizontalTabs());
    }

<!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" xmlns:m="urn:import:gwt.material.design.client.ui">
    <g:HTMLPanel>
        <h2>Your files</h2>
        <m:MaterialRow>
            <m:MaterialRow ui:field="row">
            </m:MaterialRow>
        </m:MaterialRow>
    </g:HTMLPanel>
</ui:UiBinder>

Everythink编译好。但是当我尝试进入包含此小部件的视图时会出现问题。

这是堆栈跟踪:

SEVERE: Exception caught: Exception caught: Exception caught: Exception caught: Exception caught: Exception caught: (TypeError) : Cannot read property 'hash' of undefinedcom.google.gwt.user.client.ui.AttachDetachException: Exception caught: Exception caught: Exception caught: Exception caught: Exception caught: Exception caught: (TypeError) : Cannot read property 'hash' of undefined
    at Unknown.fillInStackTrace_0_g$(cms-0.js@3:8443)
    at Unknown.Throwable_3_g$(cms-0.js@8:8398)
    at Unknown.Exception_3_g$(cms-0.js@18:8541)
    at Unknown.RuntimeException_3_g$(cms-0.js@18:8582)
    at Unknown.UmbrellaException_3_g$(cms-0.js@25:36497)
    at Unknown.UmbrellaException_5_g$(cms-0.js@26:36558)
    at Unknown.AttachDetachException_1_g$(cms-0.js@26:55009)
    at Unknown.tryCommand_1_g$(cms-0.js@11:55065)
    at Unknown.doAttachChildren_1_g$(cms-0.js@3:54662)
    at Unknown.onAttach_2_g$(cms-0.js@8:54494)
    at Unknown.setParent_2_g$(cms-0.js@12:54590)
    at Unknown.adopt_0_g$(cms-0.js@14:54649)
    at Unknown.add_14_g$(cms-0.js@8:54707)
    at Unknown.add_13_g$(cms-0.js@8:54700)
    at Unknown.add_66_g$(cms-0.js@8:77215)
    at Unknown.add_11_g$(cms-0.js@8:54637)
    at Unknown.add_65_g$(cms-0.js@43:77211)
    at Unknown.setPanelContent_0_g$(cms-0.js@54:114885)
    at Unknown.setInSlot_7_g$(cms-0.js@25:107982)
    at Unknown.setInSlot_1_g$(cms-0.js@25:73077)
    at Unknown.setInSlot_0_g$(cms-0.js@8:73066)
    at Unknown.execute_27_g$(cms-0.js@30:76290)
    at Unknown.$executeScheduled_0_g$(cms-0.js@40:11660)
    at Unknown.runScheduledTasks_0_g$(cms-0.js@9:11382)
    at Unknown.flushPostEventPumpCommands_0_g$(cms-0.js@5:11474)
    at Unknown.execute_5_g$(cms-0.js@22:11613)
    at Unknown.execute_4_g$(cms-0.js@19:11350)
    at Unknown.apply_0_g$(cms-0.js@28:10845)
    at Unknown.entry0_0_g$(cms-0.js@16:10901)
    at Unknown.anonymous(cms-0.js@14:10881)
    at Unknown.callback_0_g$(cms-0.js@45:11401)
Caused by: com.google.gwt.user.client.ui.AttachDetachException: Exception caught: Exception caught: 

我认为这是一个愚蠢的问题,但我真的找不到解决方案。请帮忙。

也许有找到原因的方法,但对我来说,当我需要找到运行时异常时,很难调试GWT应用程序。

1 个答案:

答案 0 :(得分:0)

可能是我没有任何公共getter和setter以及widget模型对象的构造函数。但现在我不确定。它开始起作用了。