From 28647eeef4fb950f48f4b81af1efd7d8bf9307a2 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Thu, 5 Jan 2023 08:34:17 +0100 Subject: [PATCH] Fix NPE which makes BlissLauncher crash --- .../features/weather/WeatherUpdater.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java index caa76ee31f..d689506dc7 100644 --- a/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/weather/WeatherUpdater.java @@ -17,6 +17,7 @@ import androidx.core.location.LocationManagerCompat; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; @@ -243,10 +244,20 @@ public class WeatherUpdater { String countryCode = Locale.getDefault().getCountry().toLowerCase(Locale.ROOT); if (!locales.has(countryCode)) { - countryCode = locales.get("en").getAsString(); + final JsonElement jsonElement = locales.get("en"); + if (jsonElement == null) { + return; + } + + countryCode = jsonElement.getAsString(); + } + + final JsonElement jsonElement = locales.get(countryCode); + if (jsonElement == null) { + return; } - final String city = locales.get(countryCode).getAsString(); + final String city = jsonElement.getAsString(); notifyUi(city); } -- GitLab