Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Swing / AWT / SWT and the fly likes org.eclipse.swt.SWTException: Invalid thread access Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "org.eclipse.swt.SWTException: Invalid thread access" Watch "org.eclipse.swt.SWTException: Invalid thread access" New topic
Author

org.eclipse.swt.SWTException: Invalid thread access

sanjaynkumar kumar
Greenhorn

Joined: Aug 06, 2006
Posts: 2
Running into this error...please help.

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 tried to implement the solution provided in the SWT FAQ. Not sure I am doing it right..

I was able to reproduce the error using this simplified version of what I doing 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
}
}
sanjaynkumar kumar
Greenhorn

Joined: Aug 06, 2006
Posts: 2
Any suggestion anyone.. i have posted the snippet of code earliar... let me know if you need more details
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: org.eclipse.swt.SWTException: Invalid thread access
 
Similar Threads
swt threads
SWT XML Sprite Sheet Utility
Using Eclipse SWT Image, JDBC SQLite and JAVA to insert, store and retrieve Images.
Making real time digital clock using RCP.
Getting "SWTException: Invalid thread access"