From 2e1b20051abd1748eb35bc2a0bcdc249964f6028 Mon Sep 17 00:00:00 2001 From: akaessens <24660231+akaessens@users.noreply.github.com> Date: Sat, 26 Sep 2020 23:00:23 +0200 Subject: [PATCH] fix nullptr crash on killing asyncs --- .../java/com/akdev/nofbeventscraper/FbScraper.java | 11 ++++++++--- .../java/com/akdev/nofbeventscraper/MainActivity.java | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java b/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java index f05b67b..295d86d 100644 --- a/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java +++ b/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java @@ -131,9 +131,14 @@ public class FbScraper { * cancel vestigial async tasks */ void killAllTasks() { - for (AsyncTask task : tasks) { - task.cancel(true); - task = null; + + try { + for (AsyncTask task : tasks) { + task.cancel(true); + task = null; + } + } catch (Exception e) { + e.printStackTrace(); } } diff --git a/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java b/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java index cc48272..113d575 100644 --- a/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java +++ b/app/src/main/java/com/akdev/nofbeventscraper/MainActivity.java @@ -172,7 +172,9 @@ public class MainActivity extends AppCompatActivity { public void onClick(View view) { input_helper(getString(R.string.helper_add_link), true); edit_text_uri_input.setText(null); - scraper.killAllTasks(); + if (scraper != null) { + scraper.killAllTasks(); + } input_helper(getString(R.string.helper_add_link), false); } };