我们有一个应用:swing写的客户端软件,其中有个email button的写邮件操作。在实现整个功能之后,我测试了很多遍都没有出现什么问题。但是我的一位同事,在连续的拷贝,粘贴,删除,保存,email之后,出现了如下的error:
[2012-09-13 16:32:15,351] FATAL [AWT-EventQueue-0] (post_mail:SelectedSizingResultPanel.java:345) : - error
org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:3884)
at org.eclipse.swt.SWT.error(SWT.java:3799)
at org.eclipse.swt.SWT.error(SWT.java:3770)
at org.eclipse.swt.widgets.Widget.error(Widget.java:463)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:282)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:273)
at org.eclipse.swt.widgets.Shell.<init>(Shell.java:223)
at view.SendEmail.execute(SendEmail.java:26)
......
因为我重现不了,这个情况,强烈要求同事重新操作,重现这个error,可是不管后来怎么操作,都无法再现。
于是我只好根据上面的log,和具体的代码来查找原因。
错误出现在shell这个地方,但是shell的代码是这样子写的。
Display display = Display.getCurrent();
Shell shell = new Shell(display);
所以我强烈怀疑是display的问题。
于是我google是Display.getCurrent()。找到如下的描述
说得到一个Display实例有两种方法,其一就是:Display.getCurrent()
A display is forever tied to the thread that created it, and a thread can have only one active display; a display is active until it is disposed of
大致是说:一个显示界面和创建它的线程永久的联系在一起,并且一个线程只能拥有一个可用的显示界面;这个显示界面在显示期间一直有效。
If you call Display.getCurrent, it returns the display that was created in that thread, if any. Here is an example:
public static Display getDisplay() {
Display display = Display.getCurrent();
//may be null if outside the UI thread
if (display == null)
display = Display.getDefault();
return display;
}
之后我查了:Display.getCurrent()和Display.getDefault()的区别
philips 写道
Display.getCurrent() 当当前代码和当前的界面(UI)线程在同一个线程时,将返回当前的Display对象。反之,当不在同一个线程时,则返回null。
Display.getDefault() 显然,针对线程使用。将返回最近的一个UI线程的Display对象。
于是我严重怀疑是我同事在连续操作的时候,导致Display.getCurrent()得到了一个null值,然后Shell shell = new Shell(display);的时候,出错了。我应该只要加上判null的代码就可以了
关于Display.getCurrent()和Display.getDefault()参考
http://jarg.iteye.com/blog/840214
分享到:
相关推荐
NULL 博文链接:https://wilian.iteye.com/blog/1992365
Caused by: android.system.ErrnoException: write failed: ENOSPC (No space lef
解决 cvc-complex-type.2.4.d: Invalid content was found 具体参考http://henatne.iteye.com/blog/837186
nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'error_view' of bean class [com.demo.controller.action.AuthorAction]: Bean property 'error_view' is not ...
invalid multibyte character sequence 870告警1
Android的MQTT消息推送接收所需jar包,修复了MqttAndroidClient会出现throw new IllegalArgumentException Invalid ClientHandle...implementation files('libs/org.eclipse.paho.android.service-1.1.1-sources.jar')
nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'transactionManagerBeanName' of bean class [org.springframework.transaction.interceptor....
大家可以直接使用 Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'URIType' of bean class [com.alibaba.citrus.service.uribroker.uri.GenericURIBroker]: Bean property ...
出现以上的情况主要的原因是因为在主配置文件标签没正确的指向映射接口的配置文件。 解决方案:1.检查的name是否正确,如我的name属性填的就是com.it.dao 2、检查的class属性或resource属性,我resource这里写的是...
STM32f10x系列的startup文件(.s文件),从例程代码里拿出来的,方便以后自己找。 ps.貌似必须收费至少1分啊。。。
Maven坐标:org.apache.yetus:audience-annotations:0.5.0; 标签:apache、yetus、audience、annotations、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览...
Maven坐标:org.apache.httpcomponents:httpcore:4.4.13; 标签:apache、httpcomponents、httpcore、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。...
再和前台对接的时候一直报错:invalid url domain 在网上查找了很多资料,有说端口的问题,也有其它各种原因的,一大堆,最后我发现以上的说法都不准确,这是我配置的地址(错误的地址) 把配置地址的http://去掉...
Nginx常见的错误和解决方法,1、Nginx 常见启动错误 有的时候初次安装nginx的时候会报这样的错误 sbin/nginx -c conf/nginx.conf 报错内容:sbin/nginx: error while loading shared libraries: libpcre.so.1: ...
Neo4j Java Reference 3.0
UDK2018环境搭建所需步骤及安装包,VS请安装2015版本,请根据自己CPU的类型(amd, intel)选择所需的安装包搭建环境。
org.springframework.beans.NotWritablePropertyException: Invalid property 'URIType' of bean class [com.alibaba.citrus.service.uribroker.uri.GenericURIBroker]: Bean property 'URIType' is not writable ...
1、ValueError: Invalid control character at: line 1 column 8363 (char 8362) 使用json.loads(json_data)时,出现: ValueError: Invalid control character at: line 1 column 8363 (char 8362) 出现错误的...
AssertionError: Invalid device id 仔细检查后发现原来服务器有多个GPU,当时开启了两个进行加速运算。 net1 = nn.DataParallel(net1, device_ids=[0, 1]) 而本地台式机只有一个GPU,调用数量超出所以报错。 改为 ...
Dubbo管理控制台(兼容JDK8)