Java SWT无效的线程访问

时间:2016-11-26 15:53:51

标签: java swt

我有一个java项目,它为两个SWT对话框提供了一些输入。有时我在启动对话框时遇到异常。我用谷歌搜索它,但发现只显示初始化问题。但我得到了shell init问题。有人可以帮我这个。

示例代码

 public static Display getDisplay ()
            {
                Display display = Display.getCurrent ();
                // may be null if outside the UI thread
                if (display == null)
                    display = Display.getDefault ();
                return display;
            }
           Display display = getDisplay(); 
           Shell shell = new Shell(display);

Excepton

org.eclipse.swt.SWTException: Invalid thread access
                at org.eclipse.swt.SWT.error(SWT.java:4441)
                at org.eclipse.swt.SWT.error(SWT.java:4356)
                at org.eclipse.swt.SWT.error(SWT.java:4327)
                at org.eclipse.swt.widgets.Widget.error(Widget.java:476)
                at org.eclipse.swt.widgets.Shell.<init>(Shell.java:283)
                at org.eclipse.swt.widgets.Shell.<init>(Shell.java:274)
                at org.eclipse.swt.widgets.Shell.<init>(Shell.java:224)
                at gui.lms.analysisRequestGUI.GenericDialog.showDialog(Unknown Source)
                at gui.teamcenter.gui.actions.PublishAction$1.execute(Unknown Source)
                at base_gui.basegui.util.WorkerThread.run(Unknown Source)

0 个答案:

没有答案