我遇到了 SWT TreeCursor 的问题。作为这个问题的示例,我将使用 Eclipse 网站中针对 TreeCursor 提供的“精确”示例:
现在,这个例子运行得很好,但是如果你点击树中的任何地方,或者使用箭头键,从而使光标出现在屏幕上,在关闭程序时,这个堆栈跟踪会抛出一个异常:
Exception in thread "main" java.lang.IllegalArgumentException: Index out of bounds
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.widgets.Widget.error(Unknown Source)
at org.eclipse.swt.widgets.Tree.getItem(Unknown Source)
at org.eclipse.swt.custom.TreeCursor$3.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Widget.release(Unknown Source)
at org.eclipse.swt.widgets.TreeItem.release(Unknown Source)
at org.eclipse.swt.widgets.Tree.releaseChildren(Unknown Source)
at org.eclipse.swt.widgets.Widget.release(Unknown Source)
at org.eclipse.swt.widgets.Control.release(Unknown Source)
at org.eclipse.swt.widgets.Composite.releaseChildren(Unknown Source)
at org.eclipse.swt.widgets.Canvas.releaseChildren(Unknown Source)
at org.eclipse.swt.widgets.Decorations.releaseChildren(Unknown Source)
at org.eclipse.swt.widgets.Shell.releaseChildren(Unknown Source)
at org.eclipse.swt.widgets.Widget.release(Unknown Source)
at org.eclipse.swt.widgets.Control.release(Unknown Source)
at org.eclipse.swt.widgets.Widget.dispose(Unknown Source)
at org.eclipse.swt.widgets.Shell.closeWidget(Unknown Source)
at org.eclipse.swt.widgets.Shell.windowShouldClose(Unknown Source)
at org.eclipse.swt.widgets.Display.windowProc(Unknown Source)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
at org.eclipse.swt.widgets.Widget.callSuper(Unknown Source)
at org.eclipse.swt.widgets.Widget.windowSendEvent(Unknown Source)
at org.eclipse.swt.widgets.Shell.windowSendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.windowProc(Unknown Source)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSendSuper(Native Method)
at org.eclipse.swt.widgets.Display.applicationSendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.applicationProc(Unknown Source)
at org.eclipse.swt.internal.cocoa.OS.objc_msgSend(Native Method)
at org.eclipse.swt.internal.cocoa.NSApplication.sendEvent(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at Snippet2.main(Snippet2.java:162)
这与您的代码无关。现在据我所知,这是 SWT 库中的一个问题,并且在处理游标时发生。从堆栈跟踪中可以看出,树项似乎是在释放游标之前释放的,因此当游标尝试访问 TreeItem 时,会发生异常。我目前正在使用一种解决方法,但我想看看是否有人对如何处理这个问题有任何想法。有什么想法吗??!!
PS:我在 Mac OS X 上并使用 SWT 4.2。