• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

org.eclipse.swt.SWTException: Invalid thread access

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any suggestion anyone.. i have posted the snippet of code earliar... let me know if you need more details
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Been there. Done that. Went back for more. But this time, I took this tiny ad with me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic