From 793a9e35490c72dde84bd1ccbabf19369cc8ec5f Mon Sep 17 00:00:00 2001 From: akaessens <24660231+akaessens@users.noreply.github.com> Date: Fri, 28 Aug 2020 21:13:21 +0200 Subject: [PATCH] prevent nullpointer exception on tests --- .../com/akdev/nofbeventscraper/FbScraper.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java b/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java index 13511d5..f39a6f7 100644 --- a/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java +++ b/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java @@ -64,8 +64,12 @@ public class FbScraper extends AsyncTask { if (matcher.find()) { - SharedPreferences shared_prefs = PreferenceManager.getDefaultSharedPreferences(main.get()); - String url_prefix = shared_prefs.getString("url_preference", "m.facebook.com"); + String url_prefix = "https://m."; + if (main != null){ + SharedPreferences shared_prefs = PreferenceManager.getDefaultSharedPreferences(main.get()); + url_prefix = shared_prefs.getString("url_preference", url_prefix); + } + // rewrite url to m.facebook and dismiss any query strings or referrals String ret = url_prefix + matcher.group(1); if (matcher.group(2) != null) { @@ -233,11 +237,13 @@ public class FbScraper extends AsyncTask { protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); - if (this.event != null) { - main.get().update(event); - } else { - main.get().error(error); - main.get().clear(false); + if (main != null) { + if (this.event != null) { + main.get().update(event); + } else { + main.get().error(error); + main.get().clear(false); + } } } }