Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

org.eclipse.swt.SWTException: Invalid thread access  RSS feed

 
sanjaynkumar kumar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any suggestion anyone.. i have posted the snippet of code earliar... let me know if you need more details
 
Damilola Okuboyejo
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try launching eclipse with the following flags: -clean -clearPersistedState

If the above still doesn't work, delete and and then restart eclipse.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!