diff --git a/app/src/main/java/ca/pkay/rcloneexplorer/Database/json/Importer.java b/app/src/main/java/ca/pkay/rcloneexplorer/Database/json/Importer.java index 2fcb7cb55..54d00e72a 100644 --- a/app/src/main/java/ca/pkay/rcloneexplorer/Database/json/Importer.java +++ b/app/src/main/java/ca/pkay/rcloneexplorer/Database/json/Importer.java @@ -33,7 +33,10 @@ public static void importJson(String json, Context context) throws JSONException public static ArrayList createTriggerlist(String content) throws JSONException { ArrayList result = new ArrayList<>(); JSONObject reader = new JSONObject(content); - JSONArray array = reader.getJSONArray("trigger"); + JSONArray array = reader.optJSONArray("trigger"); + if (array == null) { + return result; + } for (int i = 0; i < array.length(); i++) { JSONObject triggerObject = array.getJSONObject(i); result.add(Trigger.Companion.fromString(triggerObject.toString())); @@ -44,7 +47,10 @@ public static ArrayList createTriggerlist(String content) throws JSONEx public static ArrayList createTasklist(String content) throws JSONException { ArrayList result = new ArrayList<>(); JSONObject reader = new JSONObject(content); - JSONArray array = reader.getJSONArray("tasks"); + JSONArray array = reader.optJSONArray("tasks"); + if (array == null) { + return result; + } for (int i = 0; i < array.length(); i++) { JSONObject taskObject = array.getJSONObject(i); result.add(Task.Companion.fromString(taskObject.toString())); @@ -54,7 +60,10 @@ public static ArrayList createTasklist(String content) throws JSONExceptio public static ArrayList createFilterList(String content) throws JSONException { ArrayList result = new ArrayList<>(); JSONObject reader = new JSONObject(content); - JSONArray array = reader.getJSONArray("filters"); + JSONArray array = reader.optJSONArray("filters"); + if (array == null) { + return result; + } for (int i = 0; i < array.length(); i++) { JSONObject filterObject = array.getJSONObject(i); result.add(Filter.Companion.fromString(filterObject.toString()));