From 384ca6620542caee1ec787f93fa13c8d70aeacb7 Mon Sep 17 00:00:00 2001 From: Douile <25043847+Douile@users.noreply.github.com> Date: Tue, 22 Jun 2021 16:52:02 +0100 Subject: [PATCH] #6522: Fix null pointer exception when displaying SearchFragment It seems due to #6394 updating the FragmentX library there was a change to the order of lifecycle calls, as such onResume() was no longer before onCreateOptionsMenu() creating a null pointer exception when using service in onCreateOptionsMenu() as it is only set in onResume(). By moving the initialization of service to onStart() which still happens before onCreateOptionsMenu() this crash can be avoided. This commit also adds a check for a null service to prevent future crashes for similar issues. --- .../fragments/list/search/SearchFragment.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index dbf0e24dd..478cf94f3 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -227,6 +227,25 @@ public class SearchFragment extends BaseListFragment