[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Invalid thread access, but using only 1 thread

To update the UI from other threads, you must use Display#asyncExec()

Eric de Vries wrote:

I am trying to build a simple app using SWT, but ever since i changed a bit of code to use another thread for processing some objects i have, swt throws an error about invalid thread access. So after fixing it (i thought) it still throws the error. Even after removing ALL references to the other thread object, not even initializing it or using it at all, it doesnt get past the "new Display()" code

The code, without useless code

public static void main(String[] args) {
	MainFrame frame = new MainFrame();
}

public class MainFrame {
	public MainFrame() {
		createWindow();
	}

	public void createWindow() {
		Display display = new Display(); // it happens here
		// etc
	}
}

and the exception:

Exception in thread "main" org.eclipse.swt.SWTException: Invalid thread access
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.Display.checkDisplay(Unknown Source)
at org.eclipse.swt.widgets.Display.create(Unknown Source)
at org.eclipse.swt.graphics.Device.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
at kippers.gui.MainFrame.createWindow(MainFrame.java:96)
at kippers.gui.MainFrame.<init>(MainFrame.java:57)
at kippers.Main.main(Main.java:25)

Notice how it says: Exception in thread "main"

What is the cause of this error? And how do i solve this? Im pretty clueless about this one, because it happens at the initialization of the Display object, and i read the main thread is determined by the thread the "new Display()" code is called in!

Seriously, i cant figure this one out