[Android] Avoid NPE with position out of range

Geoffrey Métais git at videolan.org
Wed Mar 11 17:27:11 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar 11 14:43:52 2015 +0100| [b2b686f2f04e9d50aecdc09a9269ab7fa100e921] | committer: Geoffrey Métais

Avoid NPE with position out of range

Verify position earlier in adapter and notify on adapter clear

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=b2b686f2f04e9d50aecdc09a9269ab7fa100e921
---

 .../src/org/videolan/vlc/gui/video/VideoGridFragment.java  |    2 +-
 .../src/org/videolan/vlc/gui/video/VideoListAdapter.java   |   12 +++---------
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index b8543ce..1c35c08 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -420,8 +420,8 @@ public class VideoGridFragment extends BrowserFragment implements ISortable, IVi
         else
             Log.w(TAG, "Can't generate thumbnails, the thumbnailer is missing");
 
+        mVideoAdapter.setNotifyOnChange(true);
         mVideoAdapter.clear();
-        mVideoAdapter.notifyDataSetChanged();
 
         if (itemList.size() > 0) {
             new Thread(new Runnable() {
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index 3d37bfc..043821b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -166,6 +166,9 @@ public class VideoListAdapter extends ArrayAdapter<MediaWrapper>
             holder = (ViewHolder) v.getTag();
         }
 
+        if (position >= getCount() || position < 0)
+            return v;
+
         holder.more.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {
@@ -259,13 +262,4 @@ public class VideoListAdapter extends ArrayAdapter<MediaWrapper>
     public boolean isListMode() {
         return mListMode;
     }
-
-    @Override
-    @Nullable
-    public MediaWrapper getItem(int position) {
-        if (position < getCount() && position >= 0)
-            return super.getItem(position);
-        else
-            return null;
-    }
 }



More information about the Android mailing list