我对 GWT 很陌生。我想扩展一些标准小部件以满足我的需要。我创建了我的第一个小部件HorizontalTabs
,它扩展了 GWT MaterialDesign 的类(这里是演示,这里是源代码)我收到一个错误: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 应用程序非常困难。