[英]Why does BufferedWriter refuse to write a file?
I am making a snake game for my class project in school. 我正在学校为我的班级项目制作一个蛇游戏。 Everything was fine until I looked at my code. 一切都很好,直到我查看我的代码。 It produced no errors when I "build" it but returns NumberFormatException. 当我“构建”它但它返回NumberFormatException时它没有产生任何错误。
PS I am only a 1st year college student. PS我只是大学一年级学生。 Please be gentle 请温柔
private void checkScore() throws IOException{
try{
bw = new BufferedWriter(new FileWriter("scores.txt"));
if(score > Integer.parseInt(highest)){
highest = Integer.toString(score);
} else {
}
}catch(IOException e){
}
bw.write(score);
bw.close();
}
The result I want from this is that when a player ends the game, the score would get recorded. 我想要的结果是,当玩家结束游戏时,得分将被记录下来。 If its a high score then it would be recorded in a scores.txt file. 如果它的分数很高,那么它将记录在scores.txt文件中。 But my BufferedWriter refuses to write a file which results to the error mentioned. 但我的BufferedWriter拒绝写一个文件,导致上述错误。
The problem is that highest
has not a valid integer value when you do Integer.parseInt(highest)
. 问题是当你执行Integer.parseInt(highest)
时, highest
值没有有效的整数值。 Use debug options to see which value contains and fix that problem. 使用调试选项查看包含哪个值并修复该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.