Java: 线程访问无效 - 弹出菜单
Java: Invalid thread access - pop up menu
在 eclipse 插件中,我试图创建一个弹出窗口 window,它会在编辑器中激活,并根据在弹出窗口 window 中选择的内容向字符串添加语法。我有一个扩展 AbstractTextEditor 的编辑器 class,在其中我试图使用一个 keylistener 弹出一个包含字符串操作函数列表的 window,然后当列表中的一个项目被选中时我想要用弹出窗口中的方法返回的新字符串替换某些选定的内容 window。当我尝试这样做时(使用 2 个链接文件中的代码),我收到以下错误:
Exception in thread "AWT-EventQueue-0" org.eclipse.swt.SWTException:
Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:4595)
at org.eclipse.swt.SWT.error(SWT.java:4510)
at org.eclipse.swt.SWT.error(SWT.java:4481)
at org.eclipse.swt.widgets.Widget.error(Widget.java:451)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:369)
at org.eclipse.swt.custom.StyledText.getSelectionRange(StyledText.java:4743)
at githubflavoredmarkdowneclipseplugin.MarkdownEditor.test(MarkdownEditor.java:140)
at autocomplete.AutoComplete.keyPressed(AutoComplete.java:50)
at java.awt.AWTEventMulticaster.keyPressed(Unknown Source)
at java.awt.Component.processKeyEvent(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown
Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown
Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access0(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown
Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown
Source)
at java.awt.EventQueue.run(Unknown Source)
at java.awt.EventQueue.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown
Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
似乎当自动更新 class 试图通知编辑器 class 已选择更改时,它无法操作 styledText 变量。有谁知道如何解决这一问题?
可以通过以下链接查看包含此代码的两个文件:
http://www.filedropper.com/markdowneditor
http://www.filedropper.com/autocomplete
您收到该异常的原因是,当您进行与 SWT 相关的 UI 更改时,您必须执行可运行的 vis Display.syncExec(myRunable),否则将发生该异常。
在 eclipse 插件中,我试图创建一个弹出窗口 window,它会在编辑器中激活,并根据在弹出窗口 window 中选择的内容向字符串添加语法。我有一个扩展 AbstractTextEditor 的编辑器 class,在其中我试图使用一个 keylistener 弹出一个包含字符串操作函数列表的 window,然后当列表中的一个项目被选中时我想要用弹出窗口中的方法返回的新字符串替换某些选定的内容 window。当我尝试这样做时(使用 2 个链接文件中的代码),我收到以下错误:
Exception in thread "AWT-EventQueue-0" org.eclipse.swt.SWTException: Invalid thread access at org.eclipse.swt.SWT.error(SWT.java:4595) at org.eclipse.swt.SWT.error(SWT.java:4510) at org.eclipse.swt.SWT.error(SWT.java:4481) at org.eclipse.swt.widgets.Widget.error(Widget.java:451) at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:369) at org.eclipse.swt.custom.StyledText.getSelectionRange(StyledText.java:4743) at githubflavoredmarkdowneclipseplugin.MarkdownEditor.test(MarkdownEditor.java:140) at autocomplete.AutoComplete.keyPressed(AutoComplete.java:50) at java.awt.AWTEventMulticaster.keyPressed(Unknown Source) at java.awt.Component.processKeyEvent(Unknown Source) at javax.swing.JComponent.processKeyEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source) at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source) at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source) at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source) at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access0(Unknown Source) at java.awt.EventQueue.run(Unknown Source) at java.awt.EventQueue.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.run(Unknown Source) at java.awt.EventQueue.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
似乎当自动更新 class 试图通知编辑器 class 已选择更改时,它无法操作 styledText 变量。有谁知道如何解决这一问题?
可以通过以下链接查看包含此代码的两个文件: http://www.filedropper.com/markdowneditor http://www.filedropper.com/autocomplete
您收到该异常的原因是,当您进行与 SWT 相关的 UI 更改时,您必须执行可运行的 vis Display.syncExec(myRunable),否则将发生该异常。