进击的小小学生 2009-04-13 21:50 采纳率: 0%
浏览 249
已采纳

使用treeViewer.setInput的问题?谢谢各位...

程序报:treeViewer.setInput(root);此处出错...
我找不错什么原因,请各位帮忙解答,谢谢...
protected Control createContents(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 2;
container.setLayout(gridLayout);

    treeViewer = new TreeViewer(container, SWT.BORDER);
    tree = treeViewer.getTree();
    tree.setLayoutData(new GridData(SWT.DEFAULT, 291));
    //加载树
    Button button = new Button(container, SWT.NONE);
    button.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            //-------------------------
            TreeNode root = new TreeNode("root");
            treeViewer.setLabelProvider(new TreeLableProvider());
            treeViewer.setContentProvider(new TreeContentProvider());

            root.children.clear();
            TreeNode china = new TreeNode("China",root);
            TreeNode shanghai = new TreeNode("Shanghai",china);
            shanghai.addChild("a");
            shanghai.addChild("b");

            treeViewer.setInput(root);
        }
    });
    button.setText("确定");
    //
    return container;
}

报错内容:
org.eclipse.core.runtime.AssertionFailedException: null argument:
at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:86)
at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:74)
at org.eclipse.jface.viewers.StructuredViewer.assertElementsNotNull(StructuredViewer.java:578)
at org.eclipse.jface.viewers.StructuredViewer.getRawChildren(StructuredViewer.java:938)
at org.eclipse.jface.viewers.ColumnViewer.getRawChildren(ColumnViewer.java:703)
at org.eclipse.jface.viewers.AbstractTreeViewer.getRawChildren(AbstractTreeViewer.java:1330)
at org.eclipse.jface.viewers.TreeViewer.getRawChildren(TreeViewer.java:385)
at org.eclipse.jface.viewers.AbstractTreeViewer.getFilteredChildren(AbstractTreeViewer.java:636)
at org.eclipse.jface.viewers.AbstractTreeViewer.getSortedChildren(AbstractTreeViewer.java:602)
at org.eclipse.jface.viewers.AbstractTreeViewer.updateChildren(AbstractTreeViewer.java:2567)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefreshStruct(AbstractTreeViewer.java:1856)
at org.eclipse.jface.viewers.TreeViewer.internalRefreshStruct(TreeViewer.java:711)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefresh(AbstractTreeViewer.java:1831)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefresh(AbstractTreeViewer.java:1787)
at org.eclipse.jface.viewers.AbstractTreeViewer.internalRefresh(AbstractTreeViewer.java:1773)
at org.eclipse.jface.viewers.StructuredViewer$7.run(StructuredViewer.java:1430)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1365)
at org.eclipse.jface.viewers.TreeViewer.preservingSelection(TreeViewer.java:397)
at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1328)
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1428)
at org.eclipse.jface.viewers.ColumnViewer.refresh(ColumnViewer.java:537)
at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1387)
at org.eclipse.jface.viewers.ContentViewer.setLabelProvider(ContentViewer.java:305)
at org.eclipse.jface.viewers.StructuredViewer.setLabelProvider(StructuredViewer.java:2089)
at org.eclipse.jface.viewers.ColumnViewer.setLabelProvider(ColumnViewer.java:365)
at com.dev.jena.ui.JenaAppTree$1.widgetSelected(JenaAppTree.java:57)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at com.dev.jena.ui.JenaAppTree.main(JenaAppTree.java:124)

  • 写回答

2条回答 默认 最新

  • lggegegmail 2009-04-14 09:46
    关注

    TreeLableProvider
    的getText方法不能返回null的值, 如果是null应该返回""

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化