Eclipse Question:

Download Job Interview Questions and Answers PDF

Why do I get the error "org.eclipse.swt.SWTException: Invalid thread access"?

Eclipse Interview Question
Eclipse Interview Question

Answer:

SWT implements a single-threaded UI model often called apartment threading. In this model, only the UI-thread can invoke UI operations. SWT strictly enforces this rule. If you try and access an SWT object from outside the UI-thread, you get the exception "org.eclipse.swt.SWTException: Invalid thread access". The following code sets the text of a label from a background thread and waits for the operation to complete: display.syncExec( new Runnable() { public void run(){ label.setText(text); } });

Download Eclipse Interview Questions And Answers PDF

Previous QuestionNext Question
How to fire a key event in my test code to make the program act as if a user pressed a key?How to config a plugin to start automatically during platform starts up?