从Tree到TreeViewer控件

时间:2011-08-04 10:47:25

标签: java eclipse eclipse-plugin swt eclipse-rcp

我有这段代码

TreeViewer m_treeViewer = new TreeViewer(m_myTree);

我正在尝试使用树控件初始化树形视图控件。树控件以这种方式初始化

m_myTree= new Tree(parent, SWT.VIRTUAL);
setTreeItemListener(); // Add a double mouse click listener

// Code to populate the tree control..

m_myTree.pack();

但每次我在树控件中选择一个项时,TreeViewer控件都会失败并显示以下堆栈日志

!ENTRY org.eclipse.ui 4 0 2011-08-04 12:40:17.944
!MESSAGE Unhandled event loop exception
!STACK 0
org.eclipse.core.runtime.AssertionFailedException: **null argument**:
    at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:85)
    at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:73)
    at org.eclipse.jface.viewers.AbstractTreeViewer.**getTreePathFromItem**(AbstractTreeViewer.java:2870)
    at org.eclipse.jface.viewers.**AbstractTreeViewer.getSelection**(AbstractTreeViewer.java:2893)
    at org.eclipse.jface.viewers.StructuredViewer.handleSelect(StructuredViewer.java:1190)
    at org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected(StructuredViewer.java:1220)
    at org.eclipse.jface.util.OpenStrategy.**fireSelectionEvent**(OpenStrategy.java:228)
    at org.eclipse.jface.util.OpenStrategy.access$4(OpenStrategy.java:222)
    at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:389)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4066)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3657)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1384)

我想不出来,请帮我一把。我尝试关联一个空白的ILazyTreePathContentProvider,但它也失败了

2 个答案:

答案 0 :(得分:2)

我想,因为没有为观众分配输入。

答案 1 :(得分:0)

单击“添加”按钮时出现类似错误。我正在使用Tableviewer并尝试使用以下两种语法

m_tableViewer.setSelection(new StructuredSelection(workplaceDetail), true);

m_tableViewer.setInput(workplaceDetail);