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.
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:
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.
I’m very noob on swt so I don’t have a clue what is happening here. Can you advise?
Many thx.
This seems like a timing problem (likely on 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. You could try to cache the shell before opening message box and use the same one for file dialog.