3

コードでファイルチューザーを使用しようとしていますが、でエラーが発生"Not an enclosing class""int returnVal = fc.showOpenDialog(FileChooserDemo.this);"ます。以下は私のコードです。ANyはそれを解決すると思いますか?

browse_button.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {

     int returnVal = fc.showOpenDialog(FileChooserDemo.this);

      File file = fc.getSelectedFile();

                log.append("Opening: " + file.getAbsolutePath() + "." + "\n");
                String ab=file.getAbsolutePath();
                System.out.println(ab);

}});

actionlistenerinmainメソッドを作成しました。

4

1 に答える 1

3

問題は、静的メソッドでこの呼び出しを行っており、この静的メソッド内で(囲んでいるクラスへの参照)main(...)を使用しようとしていることです。静的な世界FileChooserDemo.thisには存在しないため、これは機能しません。this解決策は、非静的メソッドやクラスのコンストラクターなどの非静的コードでこれを行うことです。

于 2012-09-23T04:55:53.143 に答える