2012-03-14 12 views
1

これで数時間は苦労しています。私はいくつかのswtコードを実行しようとしていますが、このIllegalArgumentExceptionが発生していると私はなぜかの手がかりを持っていません。SWT java.lang.IllegalArgumentException:引数をnullにすることはできません。

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コードです:

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; 
} 

私が最初getLogFileImportLocationを呼び出す順序を変更した後、メッセージボックスを表示した場合のライン

FileDialog fd = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN); 

は常に、

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) 

を与えますこの問題はMessageBoxの初期化で発生します。

私はswtで非常にnoobだから私はここで何が起こっているか分からない。アドバイスできますか?

多くのthx。

答えて

1

タイミング問題のようです(Linuxの可能性があります)。私は、あなたがファイルダイアログのためにgetActiveShell()と呼ぶ瞬間に、メッセージボックスのダイアログが閉じられ、シェルがアクティブではないということを推測しています。あなたは、メッセージボックスを開く前にシェルをキャッシュし、ファイルダイアログのために同じものを使うことができます。

+0

Thx、それでした! :) – HugoFS

0

デバッグしましたか?ここからは、これがnullであるようだ。

Display.getCurrent().getActiveShell() 

私はこれを理解するために多くのコードが必要になりますので、私はenverionmentについてあまりにも多くの情報を持っていないが、私はこのしようとするだろう:

Shell newShell = new Shell(Display.getCurrent() == null ? Display.getDefault() : Display.getCurrent(), SWT.NO_TRIM) 

新しいシェルを取得する

+0

新しいシェルを作成することによって問題はありますか?申し訳ありませんが、私が言ったように、私はSWTには新しく、まだシーンの背後にあるコンセプトは見ていませんでした... – HugoFS

関連する問題