From 9d5836e291e0345cb13125a69e7cdd95dc545982 Mon Sep 17 00:00:00 2001 From: aiman-al-masoud Date: Sun, 18 Jul 2021 04:15:03 +0200 Subject: [PATCH] Fixed crashing bug in Settings. Tested on Nougat. --- .../noadpadlight/control/classes/Paths.java | 2 +- .../noadpadlight/control/classes/Settings.java | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/luxlunaris/noadpadlight/control/classes/Paths.java b/app/src/main/java/com/luxlunaris/noadpadlight/control/classes/Paths.java index 8aef391..4a07a98 100644 --- a/app/src/main/java/com/luxlunaris/noadpadlight/control/classes/Paths.java +++ b/app/src/main/java/com/luxlunaris/noadpadlight/control/classes/Paths.java @@ -9,7 +9,7 @@ */ public class Paths { - public static String APP_DIR_PATH = MainActivity.CONTEXT.getFilesDir().getPath(); + public static String APP_DIR_PATH = MainActivity.CONTEXT.getFilesDir().getPath(); } diff --git a/app/src/main/java/com/luxlunaris/noadpadlight/control/classes/Settings.java b/app/src/main/java/com/luxlunaris/noadpadlight/control/classes/Settings.java index a063848..93cbe75 100644 --- a/app/src/main/java/com/luxlunaris/noadpadlight/control/classes/Settings.java +++ b/app/src/main/java/com/luxlunaris/noadpadlight/control/classes/Settings.java @@ -54,7 +54,7 @@ public static boolean getBoolean(SETTINGS_TAGS TAG_NAME){ try { return settingsFile.getBoolean(TAG_NAME.toString()); - } catch (WrongTagTypeException e) { + } catch (WrongTagTypeException | NullPointerException e) { e.printStackTrace(); } @@ -76,7 +76,7 @@ public static int getInt(SETTINGS_TAGS TAG_NAME){ try { return settingsFile.getInt(TAG_NAME.toString()); - } catch (WrongTagTypeException e) { + } catch (WrongTagTypeException | NullPointerException e) { e.printStackTrace(); } @@ -97,7 +97,14 @@ public static String getString(SETTINGS_TAGS TAG_NAME){ //set up all instance attributes makeInstance(); - return settingsFile.getString(TAG_NAME.toString()); + try{ + return settingsFile.getString(TAG_NAME.toString()); + }catch (NullPointerException e){ + } + + //return the default value of the tag + return (String) TAG_NAME.DEFAULT_VAL; + } @@ -114,7 +121,7 @@ public static double getFloat(SETTINGS_TAGS TAG_NAME){ try { return settingsFile.getFloat(TAG_NAME.toString()); - } catch (WrongTagTypeException e) { + } catch (WrongTagTypeException | NullPointerException e) { e.printStackTrace(); }