我正在制作一款安卓游戏。 现在我想保存用户的高分。我决定使用文件来保存这些数据。 该应用程序之前运行良好,但现在每次调用setHighscore()或getHighscore()方法时它都会崩溃。附上可能需要的每段代码以便查看问题。我感谢每一个答案!
App.class:
public class App extends Application {
private static Context context;
private static File directory;
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
directory = getFilesDir();
}
public static Context getContext() {
return context;
}
public static File getDirectory() { return directory; }
}
Highscore.class:
public class Highscore {
public static void setHighscore(int highscore) throws IOException {
FileUtils.saveData(FILE_HIGHSCORE(), highscore+"");
}
public static int getHighscore(int highscore) throws IOException {
return Integer.parseInt(getData(FILE_HIGHSCORE()));
}
private static File FILE_HIGHSCORE() throws IOException {
return getFile("PLAYER_HIGHSCORE.txt", DIRECTORY_MAIN);
}
}
如果你想看看另一个班级/方法,请告诉我!