From 8f154f8c2166cde47bee2988c8a1255d6041978c 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