0

我正在尝试为我的 GWT 应用程序创建一个 CellTree,在初始化 Showcase [即 onModuleLoad] 期间,我收到以下错误。我要做的就是复制 GWT Showcase应用程序并从头开始构建。

17:47:04.519 [ERROR] [ChannelView] Failed to create an instance of 
'com.app.capture.client.ClientFactory' via deferred binding 
java.lang.IllegalStateException: TreeNode no longer exists.
at com.google.gwt.user.cellview.client.CellTreeNodeView$TreeNodeImpl.assertNotDestroyed(CellTreeNodeView.java:653)
at com.google.gwt.user.cellview.client.CellTreeNodeView$TreeNodeImpl.setChildOpen(CellTreeNodeView.java:642)
at com.google.gwt.user.cellview.client.CellTreeNodeView$TreeNodeImpl.setChildOpen(CellTreeNodeView.java:637)
at com.app.capture.client.ui.MainMenuViewImpl.<init>(MainMenuViewImpl.java:35)
at com.app.capture.client.ClientFactory.<clinit>(ClientFactory.java:13)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.google.gwt.dev.shell.ModuleSpace.loadClassFromSourceName(ModuleSpace.java:665)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:468)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
at com.google.gwt.core.shared.GWT.create(GWT.java:57)
at com.google.gwt.core.client.GWT.create(GWT.java:85)
at com.app.capture.client.ChannelViewEntryPoint.onModuleLoad(ChannelViewEntryPoint.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:406)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:526)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Thread.java:722)

UI 由 2 个并排垂直放置的面板组成。左侧是导航面板,我想在其中添加单元树。

celltree 视图模型类是

package com.app.capture.client.ui.model;
import java.util.ArrayList;
import java.util.List;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SingleSelectionModel;
import com.google.gwt.view.client.TreeViewModel;

public class MainMenuViewModel implements TreeViewModel {

private static class Category {
    private final String       name;
    private final List<String> items = new ArrayList<String>();

    public Category(final String name) {
        this.name = name;
    }

    public List<String> getItems() {
        return this.items;
    }

    public String getName() {
        return this.name;
    }

    public void addCategoryItem(String item) {
        items.add(item);
    }
}

private final List<Category>               categories;
private final SingleSelectionModel<String> selectionModel = new SingleSelectionModel<String>();

public MainMenuViewModel() {
    categories = new ArrayList<Category>();

    Category apg = new Category("A");
    apg.addCategoryItem("11");
    apg.addCategoryItem("22");

    Category channel = new Category("B");
    channel.addCategoryItem("33");
    channel.addCategoryItem("44");
    channel.addCategoryItem("55");

    categories.add(apg);
    categories.add(channel);
}

@Override
public <T> NodeInfo<?> getNodeInfo(T value) {
    if (value == null) {
        // Root Level
        ListDataProvider<Category> dataProvider = new ListDataProvider<Category>(categories);
        Cell<Category> cell = new AbstractCell<Category>() {
            @Override
            public void render(com.google.gwt.cell.client.Cell.Context context, Category value, SafeHtmlBuilder sb) {
                if (value != null) {
                    sb.appendEscaped(value.getName());
                }
            }
        };
        return new DefaultNodeInfo<Category>(dataProvider, cell);
    } else if (value instanceof Category) {
        ListDataProvider<String> dataProvider = new ListDataProvider<String>(((Category) value).getItems());            
        return new DefaultNodeInfo<String>(dataProvider, new TextCell(), selectionModel, null);
    }
    return null;
}

@Override
public boolean isLeaf(Object value) {
    if (value instanceof String) {
        return true;
    }
    return false;
}

}

我对主菜单视图的类定义是

public class MainMenuViewImpl extends Composite implements MainMenuView {

interface MainMenuViewImplUiBinder extends UiBinder<Widget, MainMenuViewImpl> {
}

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

private Presenter                       presenter;

@UiField(provided = true)
CellTree                                mainMenu;

private MainMenuViewModel mainMenuModel;

public MainMenuViewImpl() {
    mainMenuModel = new MainMenuViewModel();
    mainMenu = new CellTree(mainMenuModel, null);
    mainMenu.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
    TreeNode treeNode = mainMenu.getRootTreeNode();
    // This is where the exception is throw. If i remove the following line, no menu is displayed
    treeNode.setChildOpen(0, true);
    initWidget(uiBinder.createAndBindUi(this));

}

@Override
public void setPresenter(Presenter presenter) {
    this.presenter = presenter;
}

}

我的主菜单的 UI 活页夹定义是

<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:c="urn:import:com.google.gwt.user.cellview.client">
<ui:style>
    .mainMenu {
        background-color: #d7dde8;
        border: 1px solid #c3c3c3;
    }
</ui:style>

<g:VerticalPanel styleName="{style.mainMenu}">
    <c:CellTree ui:field="mainMenu" />      
</g:VerticalPanel>
</ui:UiBinder> 

我正在使用 GWT 2.5.0。

任何调试此问题的帮助/指针将不胜感激。

4

2 回答 2

0

对于引用此内容的任何人,代码中都没有问题。我认为这个问题与Eclipse有关。

今天(发布此问题后的第二天),我执行了以下步骤。

  1. 重启 Eclipse
  2. GWT 在项目上编译
  3. 运行项目。

这解决了我的问题。

于 2013-02-16T01:08:26.723 回答
0

你必须把“initWidget”方法

initWidget(uiBinder.createAndBindUi(this));

在视图构造函数的第一行。
您的构造函数可能如下所示:

public MainMenuViewImpl() 
{
  initWidget(uiBinder.createAndBindUi(this));
  mainMenuModel = new MainMenuViewModel();
  mainMenu = new CellTree(mainMenuModel, null);
  mainMenu.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
  TreeNode treeNode = mainMenu.getRootTreeNode();
  // This is where the exception is throw. If i remove the following line, no menu is displayed
  treeNode.setChildOpen(0, true);
}

;)

于 2014-01-02T11:02:18.757 回答