GWT中的这段代码(Sidebar是一个自定义的构建sidear的):
HTML html = new HTML("
<div id=\"container\">some stuff</div>"
);
RootPanel.get("container").add(new Sidebar());
...给出那个错误:
java.lang.AssertionError: A widget that has an existing parent widget may not be added to the detach list
at com.google.gwt.user.client.ui.RootPanel.detachOnWindowClose(RootPanel.java:136)
at com.google.gwt.user.client.ui.RootPanel.get(RootPanel.java:211)
你能帮忙吗?我看过很多解释,但没有任何帮助。
谢谢+
最佳答案
我不会深入解释,因为您说您已经阅读过它们:足以说明这是一种不受支持的模式。
在您的情况下,您需要使用 HTMLPanel
而不是 HTML
小部件,并使用 HTMLPanel
的 add(Widget,String)
方法将 Sidebar
放入 container
元素中:
HTMLPanel html = new HTMLPanel("<div id='container'>some stuff</div>");
html.add(new Sidebar(), "container");
关于GWT : A widget that has an existing parent widget may not be added to the detach list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17811050/