gpt4 book ai didi

java - 如何添加复合小部件: This widget's parent does not implement HasWidgets

转载 作者:太空宇宙 更新时间:2023-11-04 08:30:53 25 4
gpt4 key购买 nike

我不断抛出错误:“这个小部件的父级没有实现 HasWidgets。梳理了网络(包括 stackoverflow),但无法找出问题所在。我知道将下载对象添加到 VerticalPanel '文本'的方式有问题,但是,我不知道为什么它会抛出它,也不知道如何修复它。此外,当我运行应用程序时,它第一次成功,只在我第二次尝试访问下载页面时抛出错误。任何帮助都会是非常感谢!

public class SIXPAC implements EntryPoint, HasWidgets
{
private VerticalPanel mainPanel = new VerticalPanel() ;
private HorizontalPanel menu = new HorizontalPanel() ;
private VerticalPanel text = new VerticalPanel() ;
private SIXPACServiceAsync services = GWT.create( SIXPACService.class ) ;

public void onModuleLoad()
{
header() ;
changePage( "about.txt" ) ;
footer() ;

RootPanel.get( "sixPac" ).add( mainPanel ) ;
mainPanel.setWidth("100%");
}

public void header()
{
menu.add( menu stuff... ) ;
mainPanel.add( menu ) ;
mainPanel.add( text ) ;
}

public void footer()
{
mainPanel.add( footer stuff... ) ;
}

public void changePage( String token )
{
if( token.equals( "download.txt" ) ) // else its download page and need to set up the forms
{
text.clear() ;
try
{
add( new Download() ) ;
}
catch( Exception e )
{
System.out.println( e ) ;
}
text.setStyleName( "contentbox" ) ;
}
}

public void add(Widget w) // tried basic implementation of the HasWidgets methods...
{
text.add( w ) ;
}

public void clear()
{

}

public Iterator<Widget> iterator() {
// TODO Auto-generated method stub
return null;
}

public boolean remove(Widget w) {
// TODO Auto-generated method stub
return false;
}
}

对于下载类,为了测试,我基本上删除了所有内容:

package com.sixpac.website.client;

导入java.util.Iterator;

public class Download extends Composite
{
private static VerticalPanel verticalPanel = new VerticalPanel();

public Download()
{
verticalPanel.setStyleName("contentbox");
initWidget( verticalPanel );
verticalPanel.setWidth("100%");

verticalPanel.add( new HTML( "<h1>Download</h1>" ) ) ;

HorizontalPanel horizontalPanel = new HorizontalPanel();
horizontalPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
horizontalPanel.setWidth("100%");
verticalPanel.add( horizontalPanel ) ;

System.out.println( "creating new login" ) ;
Login login = new Login() ;
System.out.println( "creating new register" ) ;
Register register = new Register() ;

horizontalPanel.add( login ) ;
login.setSize("75%", "310px");
horizontalPanel.setCellVerticalAlignment(login, HasVerticalAlignment.ALIGN_BOTTOM);
horizontalPanel.add( register ) ;
register.setSize("90%", "257px");
horizontalPanel.setCellVerticalAlignment(register, HasVerticalAlignment.ALIGN_BOTTOM);
setStyleName("gwt");
}

public static void downloadOk()
{
verticalPanel.add( new HTML( "<br/><br/>" ) ) ;
verticalPanel.add( new HTML( "<div class=\"contentbox downloadok\">\n\t\n<p>Thank you for downloading SIXPAC Version 0.5 (Beta).</p>\n<p>Please direct all technical questions and bug-reports to Snehit Prabhu (<a href=\"mailto:snehitp@cs.columbia.edu\">snehitp@cs.columbia.edu</a>)</p>\n\t\n<br />\n\t\n<a href=\"#\" class=\"downloadbutton\">Download SIXPAC</a>\n\n<br /><br />\n</div>\n\n\n</div><!--contentbox-->" ) ) ;
}
}

堆栈跟踪:

    02:24:14.763 [ERROR] [sixpac] Uncaught exception escaped

com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:129)
at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177)
at com.google.gwt.user.client.ui.CustomButton.onBrowserEvent(CustomButton.java:698)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
at com.google.gwt.dom.client.DOMImplStandard.dispatchEvent(DOMImplStandard.java)
at com.google.gwt.dom.client.Element$.dispatchEvent$(Element.java:142)
at com.google.gwt.user.client.ui.CustomButton.onClick(CustomButton.java:825)
at com.google.gwt.user.client.ui.PushButton.onClick(PushButton.java:190)
at com.google.gwt.user.client.ui.CustomButton.onBrowserEvent(CustomButton.java:656)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.AssertionError: This UIObject's element is not set; you may be missing a call to either Composite.initWidget() or UIObject.setElement()
at com.google.gwt.user.client.ui.UIObject.getElement(UIObject.java:527)
at com.google.gwt.user.client.ui.ComplexPanel.add(ComplexPanel.java:94)
at com.google.gwt.user.client.ui.VerticalPanel.add(VerticalPanel.java:48)
at com.sixpac.website.client.SIXPAC.changePage(SIXPAC.java:140)
at com.sixpac.website.client.SIXPAC$3.onClick(SIXPAC.java:69)
at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:54)
at com.google.gwt.event.dom.client.ClickEvent.dispatch(ClickEvent.java:1)
at com.google.gwt.event.shared.GwtEvent.dispatch(GwtEvent.java:1)
at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177)
at com.google.gwt.user.client.ui.CustomButton.onBrowserEvent(CustomButton.java:698)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:289)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
at com.google.gwt.dom.client.DOMImplStandard.dispatchEvent(DOMImplStandard.java)
at com.google.gwt.dom.client.Element$.dispatchEvent$(Element.java:142)
at com.google.gwt.user.client.ui.CustomButton.onClick(CustomButton.java:825)
at com.google.gwt.user.client.ui.PushButton.onClick(PushButton.java:190)
at com.google.gwt.user.client.ui.CustomButton.onBrowserEvent(CustomButton.java:656)
at com.google.gwt.user.client.DOM.dispatchEventImpl(DOM.java:1351)
at com.google.gwt.user.client.DOM.dispatchEvent(DOM.java:1307)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:680)

最佳答案

问题是verticalPanel在下载类中是静态的。我认为这会导致您的代码在多次调用时使用错误的引用来 initWidget 。尝试删除静电它应该可以工作。另外,您可以像实现 add 一样,通过将其传递给文本实例来实现其余的 haswidget 接口(interface)方法。

关于java - 如何添加复合小部件: This widget's parent does not implement HasWidgets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7550872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com