[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [platform-swt-dev] org.eclipse.swt.SWTException: Invalid thread access
|
You have to create the Display object within the main thread. Otherwise it throws that exception.
Daniel
On 8/6/06, Sanjay Kumar <
sankumr@xxxxxxxxxxx> wrote:Running into this error...please help. (tried SWT FAQ solution for this
issue does not work..Not sure if I am doing it right though..)
Exception in thread "5" org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:2942)
at org.eclipse.swt.SWT.error
(SWT.java:2865)
at org.eclipse.swt.SWT.error(SWT.java:2836)
at org.eclipse.swt.widgets.Display.checkDisplay(Display.java:627)
at org.eclipse.swt.widgets.Display.create(Display.java:688)
at org.eclipse.swt.graphics.Device
.<init>(Device.java:129)
at org.eclipse.swt.widgets.Display.<init>(Display.java:388)
at org.eclipse.swt.widgets.Display.<init>(Display.java:379)
at santest.test(santest.java:13)
at santest.run
(santest.java:28)
at java.lang.Thread.run(Thread.java:595)
I was able to reproduce the error using this simplified version of what I
have in my actual code
import org.eclipse.swt.graphics.*;
import
org.eclipse.swt.widgets.*;
public class santest implements Runnable {
private int countDown = 5;
public String toString() {
return "#" + Thread.currentThread().getName() +
": " + countDown;
}
public void test() {
final Display display = new Display();
display.syncExec (new Runnable () {
public void run () {
GC gc = new GC(display);
final org.eclipse.swt.graphics.Image image = new
org.eclipse.swt.graphics.Image
(display, display.getBounds());
gc.copyArea(image, 0, 0);
gc.dispose();
}
});
/* Take the screen shot */
}
public void run() {
while(true) {
System.out.println(this);
test();
if(--countDown == 0) return;
}
}
public static void main(String[] args) {
for(int i = 1; i <= 5; i++)
new Thread(new santest(), "" + i).start();
// Output is like SimpleThread.java
}
}
_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev