[英]SWT - MessageDialog - Shells
I have an operations class that has no gui. 我有一个没有gui的操作类。 The class basically does data management.
该类基本上进行数据管理。 The class is called from a method in my Main GUI.
从我的主GUI中的方法调用该类。 The problem I am having is with displaying messages to the user if something fails.
我遇到的问题是如果出现故障则向用户显示消息。 I am using
MessageDialog
, but it keeps failing at runtime. 我正在使用
MessageDialog
,但它在运行时始终失败。 I think the issue is with Shell. 我认为问题出在壳牌公司。 When I try to use
null
as the shell. 当我尝试使用
null
作为外壳程序时。
MessageDialog.openError(null, "Printer Error Message", "Error getting print reply file.");
The error is null pointer exception 错误为空指针异常
MessageDialog.openError(Display.getCurrent().getActiveShell() etc
The error is null pointer exception 错误为空指针异常
MessageDialog.openError(Display.getDefault().getActiveShell()
The error is invalid thread access 错误是无效的线程访问
You can fix the ERROR_THREAD_INVALID_ACCESS
error with Display.syncExec
or Display.asyncExec
. 您可以使用
Display.syncExec
或Display.asyncExec
修复ERROR_THREAD_INVALID_ACCESS
错误。 Try with: 尝试:
Display.syncExec(new Runnable() {
void run() {
MessageDialog.openError(Display.getDefault().getActiveShell()...
}
}
Few important points to consider. 需要考虑的几个重点。
Display.getDefault().asyncExec()
or syncExce()
Display.getDefault().asyncExec()
或syncExce()
Display.getDefault().getActiveShell()
to pass it to the dialog first, if it is null, create one and pass it. Display.getDefault().getActiveShell()
以将其传递给对话框,如果为null,则创建一个并传递给对话框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.