简体   繁体   English

SWT java.lang.IllegalArgumentException:参数不能为null

[英]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.

相关问题 java.lang.IllegalArgumentException:“原始”消息参数不能为null - java.lang.IllegalArgumentException: The 'original' message argument cannot be null java.lang.IllegalArgumentException: uri 不能是 null - java.lang.IllegalArgumentException: uri cannot be null Java swt IllegalArgumentException:参数不能为null - Java swt IllegalArgumentException: Argument cannot be null 运行测试时获取“java.lang.IllegalArgumentException:解码参数不能为空” - Getting "java.lang.IllegalArgumentException: Decode argument cannot be null" when running tests java.lang.IllegalArgumentException:[断言失败]-此参数是必需的; 它不能为空 - java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null 休眠查询java.lang.IllegalArgumentException:要遍历的节点不能为null - hibernate query java.lang.IllegalArgumentException: node to traverse cannot be null java.lang.IllegalArgumentException:迭代变量不能为null - java.lang.IllegalArgumentException: Iteration variable cannot be null ProfileCredentialsProvider:java.lang.IllegalArgumentException:配置文件不能为空 - ProfileCredentialsProvider: java.lang.IllegalArgumentException: profile file cannot be null Instagram Oauth2 java.lang.IllegalArgumentException: authorizationGrantType 不能是 null - Instagram Oauth2 java.lang.IllegalArgumentException: authorizationGrantType cannot be null java.lang.illegalargumentException:无法设置空的TableModel - java.lang.illegalargumentexception:cannot set a null TableModel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM