[Android] Prevent NPE when getting current fragment

Geoffrey Métais git at videolan.org
Mon Sep 18 15:40:24 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Sep 18 11:23:02 2017 +0200| [a3c5381c982f41db44a6262625e5b54e426aba59] | committer: Geoffrey Métais

Prevent NPE when getting current fragment

> https://code.videolan.org/videolan/vlc-android/commit/a3c5381c982f41db44a6262625e5b54e426aba59
---

 vlc-android/src/org/videolan/vlc/gui/MainActivity.java | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 30da1b9e0..a4ddbf59a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -706,9 +706,12 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
     }
 
     private Fragment getFirstVisibleFragment() {
-        for (Fragment fragment : getSupportFragmentManager().getFragments())
-            if (!fragment.isHidden() && fragment.getClass().isInstance(mCurrentFragment))
-                return fragment;
+        final List<Fragment> fragments = getSupportFragmentManager().getFragments();
+        if (fragments != null) {
+            for (Fragment fragment : fragments)
+                if (!fragment.isHidden() && fragment.getClass().isInstance(mCurrentFragment))
+                    return fragment;
+        }
         return mCurrentFragment;
     }
 



More information about the Android mailing list