使用BufferedWriter和Gdx.files.internal()时出现NullPointerException

时间:2014-12-26 09:01:16

标签: libgdx java-io

我正在尝试编写一个简单的函数,将我的播放器的配置文件保存到内部文件,但它会在outputWriter初始化时抛出NullPointerException。

    public void saveProfile(String filePath){
    BufferedWriter outputWriter;
    try{
        outputWriter = new BufferedWriter(new OutputStreamWriter(Gdx.files.local(filePath).write(false)));

        saveInfo[pid]=count;
        gamesLost=saveInfo[pgamesLost]=gamesLost;
        gamesWon=saveInfo[pgamesWon]=gamesWon;
        saveName=name;

        outputWriter.write(name+"\n");
        for(int i=0;i<saveInfo.length;i++){
            outputWriter.write(Integer.toString(saveInfo[i])+"\n");
        }

        outputWriter.close();

    }catch (Exception e) {
        e.printStackTrace();
    }
}

0 个答案:

没有答案