Android应用程序在创建文件时崩溃
我目前正在制作一款android游戏。 现在我想保存用户的高分。我决定使用文件来保存数据。 该应用程序以前工作得非常好,但现在每次调用setHighscore()或getHighscore()方法时都会崩溃。为了检查问题,您可能需要的每一段代码都附在后面。我感谢每一个答案 App.class:Android应用程序在创建文件时崩溃,android,android-studio,Android,Android Studio,我目前正在制作一款android游戏。 现在我想保存用户的高分。我决定使用文件来保存数据。 该应用程序以前工作得非常好,但现在每次调用setHighscore()或getHighscore()方法时都会崩溃。为了检查问题,您可能需要的每一段代码都附在后面。我感谢每一个答案 App.class: public class App extends Application { private static Context context; private static File directory;
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);
}
}
如果你想看另一个类/方法,请告诉我错误消息是什么?我用自己的设备(htc one(m7)mini)测试应用程序,在Android Studio中调试应用程序对我来说从来没有真正起过作用(加载需要很多时间,…)也分享错误消息。只是“不幸的是,[应用程序]已停止”请发布您的主要活动