[Android] Audio adapter: Prevent NPE

Geoffrey Métais git at videolan.org
Mon Feb 18 15:53:53 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Feb 18 10:23:53 2019 +0100| [d168fab20ff32125dab477cd82ae84d684d83107] | committer: Geoffrey Métais

Audio adapter: Prevent NPE

Items can be null while medialibrary is loading them

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

 .../org/videolan/vlc/gui/audio/AudioBrowserAdapter.java | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
index 963a604d7..39f66402f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
@@ -210,22 +210,21 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
         }
 
         public void onClick(View v) {
-            if (mIEventsHandler != null) {
-                int position = getLayoutPosition();
-                mIEventsHandler.onClick(v, position, getItem(position));
-            }
+            int position = getLayoutPosition();
+            final MediaLibraryItem item = getItem(position);
+            if (item != null) mIEventsHandler.onClick(v, position, item);
         }
 
         public void onMoreClick(View v) {
-            if (mIEventsHandler != null) {
-                int position = getLayoutPosition();
-                mIEventsHandler.onCtxClick(v, position, getItem(position));
-            }
+            int position = getLayoutPosition();
+            final MediaLibraryItem item = getItem(position);
+            if (item != null) mIEventsHandler.onCtxClick(v, position, item);
         }
 
         public boolean onLongClick(View view) {
             int position = getLayoutPosition();
-            return mIEventsHandler.onLongClick(view, position, getItem(position));
+            final MediaLibraryItem item = getItem(position);
+            return item != null && mIEventsHandler.onLongClick(view, position, item);
         }
 
         private void setCoverlay(boolean selected) {



More information about the Android mailing list