1. 程式人生 > >偶遇 :org.eclipse.swt.SWTException: Failed to execute runnable

偶遇 :org.eclipse.swt.SWTException: Failed to execute runnable

Exception in thread "main" org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)
	at org.eclipse.swt.SWT.error(SWT.java:4282)
	at org.eclipse.swt.SWT.error(SWT.java:4197)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
	at demos.common.main(Launcher.java:125)
Caused by: org.eclipse.swt.SWTException: Widget is disposed
	at org.eclipse.swt.SWT.error(SWT.java:4282)
	at org.eclipse.swt.SWT.error(SWT.java:4197)
	at org.eclipse.swt.SWT.error(SWT.java:4168)
	at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
	at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
	at org.eclipse.swt.widgets.Control.internal_new_GC(Control.java:1689)
	at org.eclipse.swt.graphics.GC.<init>(GC.java:166)
	at org.eclipse.swt.graphics.GC.<init>(GC.java:132)

SWT應用採用“左樹右內容”的結構,左邊是樹選單,通過點選樹選單,右邊顯示對應的內容,實現方式是,每點選樹的葉子結點的時候,把右邊容器的子容器全部dispose,然後再畫上新的內容。

執行一段時間,發現,某個樹節點對應的內容裡面,如果包含有thread域,則在點選其它節點的時候,會報以上的異常,這種情況應該是在dispose右邊容器的子視窗的時候,沒把執行緒給滅掉,執行緒繼續執行,這時就報錯了。

經過除錯,找到解決方法,線上程run方法裡面加上一個判斷,如果執行該執行緒的容器被dispose了,則不繼續執行執行緒,如下所示:

public void run(){
if(!composite.getParentControl().isDisposed()) {
 //do your things
}

}


加上以上判斷,點選有thread變數的節點,再點選其它節點,不會報前面所說的Exception。

相關推薦

偶遇 org.eclipse.swt.SWTException: Failed to execute runnable

Exception in thread "main" org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed) a

Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)原因以及解決辦法

以下錯誤是本人學習中碰到的,以後碰到繼續完善: SWT程式設計中,當一個類中有一個執行緒 的時候,這個shell開啟又關閉,這樣重複幾次的時候就會出現這樣一個問題: Failed to execut

org.eclipse.e4.core.di.InjectionException:org.eclipse.swt.SWTException: Widget is disposed

gin bsp pos rac org core ins exception 重新啟動 org.eclipse.e4.core.di.InjectionException:org.eclipse.swt.SWTException: Widget is dispose

解決 org.eclipse.swt.SWTException: Graphic is disposed 問題

現象:org.eclipse.swt.SWTException: Graphic is disposed 下面的例子只是其中一種提示,還有很多可能性Graphic is disposed,用著用著突然就出現了這種情況,用fix 然後關閉專案再啟動專案也只是一個xml能夠正常

springMvc啟動報錯org.apache.catalina.LifecycleException: Failed to start component

複製了一個專案,然後啟動專案是報錯一堆錯誤,如下 … org.apache.catalina.LifecycleException: Failed to start component

Exception in thread "Thread-0" org.eclipse.swt.SWTException: Invalid thread access. 錯誤解決

執行SWT GUI的應用程式是遇到異常:Exception in thread "Thread-0" org.eclipse.swt.SWTException: Invalid thread access at org.eclipse.swt.SWT.error(SWT.ja

The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path Maven專案報錯Failed to execute goal org.apache.maven.plugi

 ① The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 完整錯誤資訊: THIS SOFTWARE IS PROVIDED BY THE

maven專案啟動報錯Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2

相信很多人啟動maven專案都遇到過這種型別的錯。me too! 原因1:jdk版本跟maven版本不一致導致的。舉個例子,jdk1.6是不支援maven 2.0.2的,jdk1.7才行。 解決方案:這個得自己查詢,jdk 與 maven 版本的對應,再去java b

maven專案war包時報錯Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile

原因:缺少maven-compiler-plugin.jar包 解決:pom匯入jar包 <dependency> <groupId>org.apache.maven.plugins</groupId> <artifactId>

關於org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]Specified class is an interface

exc img interface 類型 生成 lis final spring cif 報錯原因:   spring在註入的時候不允許註入一個List類型的對象,才會導致報上訴錯誤; 解決辦法:   ①:改變為數組方式去接收;(我沒用)   ②:再把這個“List<

報錯Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:testCompile

在eclispe上執行mvn命令報錯:[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:testCompile (default-testCompile) on project VS

啟動tomcat執行maven工程報錯Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:

控制檯報錯資訊:   解決方案:在maven工程pom.xml中新增如下依賴 <dependency> <groupId>org.apache.maven.plugins</groupId> <artifactId&g

eclipse maven SLF4J: Failed to load class org.slf4j.impl.StaticLoggerBinder

現象:執行eclipse maven build,console 有紅色日誌如下: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operat

解決maven打war包報錯Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2

一、報錯經歷:今天使用eclipse通過maven install打war包的時候,出現了下圖所示的錯誤二、問題分析:不能執行依賴包maven-compiler-plugin:2.3.2,判斷原因是缺少這個jar包三、問題解決:開啟pom.xml檔案,在適當位置加入下列依賴:

idea建立maven專案沒有src目錄報錯idea Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin

方法一: 之所以沒src目錄是因為maven還沒載入好,右下角還有進度條在從中央倉庫讀,所以在建立maven專案的時候,加archetypeCatalog=internal 方法二: idea新建maven 出現這個問題,直接去倉庫下面repository\org\

Maven部署到Tomcat出現錯誤Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1

大家都知道錯誤內容相同時,出現的場景也不一定相同。所以本篇提出的錯誤解決方案可能僅僅適用跟我相同場景下的情況。 1、出現錯誤的場景: 按照我之前一篇文章【Eclipse中Maven的整合和使用介紹】進行配置Maven之後,在再src/main/java資料夾下建立Servl

解決Maven打包怪異異常Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:resource

今天在使用maven打包時正常操作卻報出瞭如題的錯誤:         Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:resource......         這個

maven打包報錯Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test

mvn compile  沒有問題,mvn package的時候報如下錯誤: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test  解決方法: 打包跳過測試有兩種

錯誤Failed to execute goal org.apache.tomcat.maven:tomcat7-maven-plugin:2.2

報錯資訊: [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] e3-manager .

maven打包報錯Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin

mvn compile  沒有問題,mvn package的時候報如下錯誤: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.5:test  解決方法: 打包跳過測試有兩種