嗨,我在应用程序中打开设置活动时遇到了问题,它会崩溃。
这是logcat错误:
07-01 05:00:34.490: E/AndroidRuntime(6496):
java.lang.ExceptionInInitializerError
07-01 05:00:34.490: E/AndroidRuntime(6496): at com.example.mehrad.hooshhafezeh.utilities.PreferencesManager.getFontSize(PreferencesManager.java:24)
这是我的PreferencesManager代码:
import android.content.SharedPreferences;
import com.example.mehrad.hooshhafezeh.application.App;
public class PreferencesManager {
private static SharedPreferences preferences;
static {
preferences =
App.getInstance().getSharedPreferences(AppConstants.SHARED_PREFERENCES, 0);
}
public static void setFontSize(int value) {
preferences.edit()
.putInt(AppConstants.FONT_SIZE, value)
.apply();
}
public static int getFontSize() {
return preferences.getInt(AppConstants.FONT_SIZE, 16);
}
public static void setTypeface(String typeFace) {
preferences.edit()
.putString(AppConstants.TYPE_FACE, typeFace)
.apply();
}
public static String getTypeface() {
return preferences.getString(AppConstants.TYPE_FACE, "");
}
public static void firstDatabaseInit(boolean first){
preferences.edit()
.putBoolean(AppConstants.INIT_DATABASE,first)
.apply();
}
public static boolean isFirstDatabaseInit(){
return preferences.getBoolean(AppConstants.INIT_DATABASE,false);
}
}
我已经编写了App和AppConstants类,但我认为方法并不重要 解决错误
我该如何解决?