用swt写了个小程序,但是运行时报如下错误:
org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:3374)
at org.eclipse.swt.SWT.error(SWT.java:3297)
at org.eclipse.swt.SWT.error(SWT.java:3268)
at org.eclipse.swt.widgets.Widget.error(Widget.java:435)
at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:331)
at org.eclipse.swt.widgets.Text.append(Text.java:241)
at db.DB.getCon(DB.java:22)
at db.DB. <init> (DB.java:11)
at search.SearchOneWeb.search(SearchOneWeb.java:258)
at search.SearchOneWeb.run(SearchOneWeb.java:50)
什么原因?怎么解决?
------解决方案--------------------
调用方式如:
final text = new Text(shell,SWT.BORDER);
................
Display.getDefault().asyncExec(new Runnable()
{
public void run()
{
text.setText( "text test! ");
}
});