当前位置: 代码迷 >> Eclipse >> SWT Failed to execute runnable 线程异常有关问题
  详细解决方案

SWT Failed to execute runnable 线程异常有关问题

热度:404   发布时间:2016-04-23 14:11:20.0
SWT Failed to execute runnable 线程错误问题
使用SWT开发时,有时候出抛出异常
Java code
org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)    at org.eclipse.swt.SWT.error(Unknown Source)    at org.eclipse.swt.SWT.error(Unknown Source)    at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Unknown Source)    at org.eclipse.swt.widgets.Display.runAsyncMessages(Unknown Source)    at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)         ...Caused by: org.eclipse.swt.SWTException: Widget is disposed    at org.eclipse.swt.SWT.error(Unknown Source)    at org.eclipse.swt.SWT.error(Unknown Source)    at org.eclipse.swt.SWT.error(Unknown Source)    at org.eclipse.swt.widgets.Widget.error(Unknown Source)    at org.eclipse.swt.widgets.Widget.getDisplay(Unknown Source)    at org.eclipse.jface.window.DefaultToolTip.getForegroundColor(DefaultToolTip.java:159)    at org.eclipse.jface.window.DefaultToolTip.createToolTipContentArea(DefaultToolTip.java:92)    at org.eclipse.jface.window.ToolTip.toolTipShow(ToolTip.java:332)    at org.eclipse.jface.window.ToolTip.access$4(ToolTip.java:329)    at org.eclipse.jface.window.ToolTip$2.run(ToolTip.java:429)    at org.eclipse.swt.widgets.Display.runTimer(Unknown Source)    at org.eclipse.swt.widgets.Display.messageProc(Unknown Source)    at org.eclipse.swt.internal.win32.OS.MessageBoxW(Native Method)    at org.eclipse.swt.internal.win32.OS.MessageBox(Unknown Source)    at org.eclipse.swt.widgets.MessageBox.open(Unknown Source)    at com.my.test.aaa(Test.java 1000)    at com.my.test.bbb.run(UITest.java:379)    at org.eclipse.swt.widgets.RunnableLock.run(Unknown Source)    ... 6 more

具体情况是:在界面上做某个操作,然后MessageBox返回消息,就会出现这种情况
比如:
Java code
public class UITest implements Runnable {    public run(){         new Thread() {            public void run() {                Display.getDefault().syncExec(new Runnable() {                public void run() {                 //执行aaa方法                }            });                        }.start();      } }}

Test类
Java code
public class Test{    public void aaa(){    //执行某个事件    MessageBox msg = essageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.YES);     msg.setText("aa");    msg.setMessage("aaaaa");    msg.open();//选择“是”,就会抛出异样    }   public static void main(String args[]){      ///   }}

这个问题在网上搜了,还没找到解决的办法,期待高手。

------解决方案--------------------
问题应该是你操作了已经dispose掉的组件,不过你的代码没贴完整,无法指出具体哪里有问题,看异常信息的这三句吧:
Caused by: org.eclipse.swt.SWTException: Widget is disposed
at com.my.test.aaa(Test.java 1000)
at com.my.test.bbb.run(UITest.java:379)

如果还是找不到原因建议贴上完整的代码吧.....
------解决方案--------------------
你可以换一下啊 
Java code
public class Test{    public void aaa(){  Display.getDefault().syncExec(new Runnable() {                public void run() {                     //执行某个事件    MessageBox msg = essageBox mb = new MessageBox(shell, SWT.ICON_INFORMATION |SWT.YES);     msg.setText("aa");    msg.setMessage("aaaaa");    msg.open();//选择“是”,就会抛出异样                }            });      }   public static void main(String args[]){      ///   }}
------解决方案--------------------
这个错误是因为界面控件已经关闭了,你还在操作控件,例如调用控件的setText()方法等...
------解决方案--------------------
  相关解决方案