程序报: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)