[英]SWT java.lang.IllegalArgumentException: Argument cannot be null
I'm struggling with this for some hours now. 我已经为此奋斗了几个小时。 I'm trying to get some swt code running but this IllegalArgumentException is happening and I don't have a clue on why. 我正在尝试运行一些swt代码,但是此IllegalArgumentException正在发生,我不知道为什么。
private void loadLogFromFile() {
MessageBox mbox = new MessageBox(Display.getCurrent().getActiveShell(),
SWT.YES | SWT.NO | SWT.ICON_QUESTION);
mbox.setText("Confirmation");
mbox.setMessage ("This operation will clear de current selected device and " +
"all logs currently being displayed. Do you wish to continue?");
final int mboxResult = mbox.open();
if (mboxResult != SWT.YES) {
return;
}
final String fName = getLogFileImportLocation();
if (fName == null) {
return;
}
}
getLogFileImportLocation code is: getLogFileImportLocation代码为:
private String getLogFileImportLocation() {
FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN);
fd.setText("Load Log..");
fd.setFileName("log.txt");
if (mLogFileImportFolder == null) {
mLogFileImportFolder = System.getProperty("user.home");
}
fd.setFilterPath(mLogFileImportFolder);
fd.setFilterNames(new String[] {
"Text Files (*.txt)"
});
fd.setFilterExtensions(new String[] {
"*.txt"
});
String fName = fd.open();
if (fName != null) {
mLogFileImportFolder = fd.getFilterPath(); /* save path to restore on future calls */
}
return fName;
}
The line 线
FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN);
Always gives 总是给
java.lang.IllegalArgumentException: Argument cannot be null
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.Dialog.error(Unknown Source)
at org.eclipse.swt.widgets.Dialog.checkParent(Unknown Source)
at org.eclipse.swt.widgets.Dialog.<init>(Unknown Source)
at org.eclipse.swt.widgets.FileDialog.<init>(Unknown Source)
If I change the order calling getLogFileImportLocation first and show MessageBox after, the issue happens in MessageBox initialization. 如果我先更改调用getLogFileImportLocation的顺序,然后再显示MessageBox,则问题发生在MessageBox初始化中。
I'm very noob on swt so I don't have a clue what is happening here. 我对swt非常陌生,所以我不知道这里发生了什么。 Can you advise? 你能建议吗?
Many thx. 很多。
This seems like a timing problem (likely on Linux). 这似乎是一个时序问题(可能在Linux上)。 I'm guessing that at the moment when you call getActiveShell()
for file dialog the message box dialog is in the process of being closed and no shell is active. 我猜想,当您为文件对话框调用getActiveShell()
,消息框对话框正在关闭中,并且没有外壳处于活动状态。 You could try to cache the shell before opening message box and use the same one for file dialog. 您可以在打开消息框之前尝试对外壳进行缓存,并将相同的对话框用于文件对话框。
Have you debugged it? 你调试了吗? From here it seems this is null: 从这里看来这是空的:
Display.getCurrent().getActiveShell()
I would need more code to figure this out, so I don't have too much information about the enverionment, but I would try this: 我需要更多代码来解决这个问题,所以我对环境没有太多了解,但是我会尝试这样做:
Shell newShell = new Shell(Display.getCurrent() == null ? Display.getDefault() : Display.getCurrent(), SWT.NO_TRIM )
to get a new shell 得到一个新的壳
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.