私のプロジェクト用に実行可能なjarファイルを作成しています。Eclipseでressourceを使用しようとするとNullPointerExceptionが発生する
コード
public class StandingsCreationHelper
{
private static final String TEMPLATE_FILENAME = "Standings_Template.xls";
public static void createStandingsFile() throws Exception
{
StandingsCreationHelper sch = new StandingsCreationHelper();
// Get the file from the resources folder
File templateFile = new File("TemporaryPlaceHolderExcelFile.xls");
OutputStream outputStream = new FileOutputStream(templateFile);
IOUtils.copy(sch.getFile(TEMPLATE_FILENAME), outputStream);
outputStream.close();
}
}
public InputStream getFile(String fileName)
{
return this.getClass().getClassLoader().getResourceAsStream(fileName);
}
public static void main(String[] args) throws Exception
{
createStandingsFile();
}
プロジェクトの構造
質問
私は実行可能なjarファイルに私のコードをパッケージ、私のプログラム問題なく実行されます。しかし、私のIDE(Eclipse)からmainメソッドを呼び出すと、リソースが見つからないかのように、次のエラーメッセージが表示されます。
スレッド "main"の例外java.lang.NullPointerException at org.apache .poi.util.IOUtils.copy事前のためのstandings.StandingsCreationHelper.main(StandingsCreationHelper.java:222)でstandings.StandingsCreationHelper.createStandingsFileで(IOUtils.java:182) (StandingsCreationHelper.java:153)
感謝どんな助けでも!
'' /resources/Standings_Template.xls '; '??? –
迅速な回答ありがとうございます。上記の文字列に変更すると、まだNULLポインタ例外が返されます。 –
null、入力または出力は何ですか? –