From d8d9c7e1710790fec0e6ae0e89d94238e463de95 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 26 Apr 2020 21:41:09 +0200 Subject: [PATCH] Fix crashes on rotation by checking for `null` --- .../newpipe/fragments/list/BaseListFragment.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index c87096712..9ce62a0df 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -131,15 +131,14 @@ public abstract class BaseListFragment extends BaseStateFragment } private int getFocusedPosition() { - View focusedItem = itemsList.getFocusedChild(); - if (focusedItem != null) { - RecyclerView.ViewHolder itemHolder = itemsList.findContainingViewHolder(focusedItem); - if (itemHolder != null) { - return itemHolder.getAdapterPosition(); - } + try { + final View focusedItem = itemsList.getFocusedChild(); + final RecyclerView.ViewHolder itemHolder = + itemsList.findContainingViewHolder(focusedItem); + return itemHolder.getAdapterPosition(); + } catch (NullPointerException e) { + return -1; } - - return -1; } @Override