Skip to content

Commit b6a94d2

Browse files
Fix ClassCastException when reading monospace font preference
1 parent 11111fb commit b6a94d2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/utils/FontManager.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
public class FontManager {
1212

1313
public static Typeface getMonospaceFont(Context context, SharedPreferences prefs) {
14-
return switch (prefs.getString(context.getString(R.string.key_monospace_font), "0")) {
14+
String key = context.getString(R.string.key_monospace_font);
15+
String font;
16+
try {
17+
font = prefs.getString(key, "0");
18+
} catch (ClassCastException e) {
19+
prefs.edit().remove(key).apply();
20+
font = "0";
21+
}
22+
return switch (font) {
1523
case "1" -> ResourcesCompat.getFont(context, R.font.font_fira_code);
1624
case "2" -> ResourcesCompat.getFont(context, R.font.font_jetbrains_mono);
1725
case "3" -> ResourcesCompat.getFont(context, R.font.font_noto_sans_mono);

0 commit comments

Comments
 (0)