私は Java で Halo: CE カスタム ゲーム ランチャーに取り組んでおり、Java の Properties クラスを使用して設定システムをセットアップしているので、ユーザーはカスタム ゲーム パスを設定できます。JFileChooser を使用してファイルを選択し、そのパスを構成ファイルに書き込みます。
ただし、プログラムは次の行で Null Pointer Exception を返します: (これはイベント リスナー関数にあります)
if(source == fovChooseButton)
{
int returnVal = chooseFile.showOpenDialog(settingsWindow);
if(returnVal == JFileChooser.APPROVE_OPTION)
{
File selected = chooseFOV.getSelectedFile();
try
{
config.setProperty("STLPath", selected.getAbsolutePath()); //This line gives the exception
config.store(new FileOutputStream(CONFIG_FILE), null);
}
catch(Exception e)
{
handleException(e);
}
}
}
別の JFileChooser がありますが、例外はスローされません。もう1つのコードは次のとおりです。
if(source == fileChooseButton)
{
int returnVal = chooseFile.showOpenDialog(settingsWindow);
if(returnVal == JFileChooser.APPROVE_OPTION)
{
File selected = chooseFile.getSelectedFile();
try
{
config.setProperty("GamePath", selected.getAbsolutePath());
config.store(new FileOutputStream(CONFIG_FILE), null);
}
catch(Exception e)
{
handleException(e);
}
} // end if
}
handleException() が行うことは、スタック トレースを含むダイアログ ウィンドウを表示することだけです。
ヘルプ?