0

I have java project, which lanches two SWT dialogs, for some input. Sometime I got below exception while launch dialog. I googled it but found only display init issue. But i got shell init issue. Can some one help me on this.

Sample Code

 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)
Jobin
  • 5,610
  • 5
  • 38
  • 53
Ganesh Kn
  • 9
  • 1
  • 2
    You appear to be trying to do a GUI operation in a background thread - this is not allowed. Look at the `asyncExec` and `syncExec` methods of `Display`. – greg-449 Nov 26 '16 at 16:03
  • This questions pops up regularly here. It's probably the most common SWT exception. [Here](http://stackoverflow.com/questions/5980316/invalid-thread-access-error-with-java-swt?rq=1) and [here](http://stackoverflow.com/questions/15851562/java-swt-and-invalid-thread-access?rq=1) are examples to look at. – Baz Nov 27 '16 at 11:32

0 Answers0