[Android] DirectoryAdapter: fix a crash for IndexOutOfBoundsException

Jean-Baptiste Kempf git at videolan.org
Tue Aug 14 12:31:30 CEST 2012


android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Tue Aug 14 12:30:35 2012 +0200| [2a3fe34fe40cb5647e9ff7f3670659b38a26464c] | committer: Jean-Baptiste Kempf

DirectoryAdapter: fix a crash for IndexOutOfBoundsException

Number 2 on the developer console

> http://git.videolan.org/gitweb.cgi/android.git/?a=commit;h=2a3fe34fe40cb5647e9ff7f3670659b38a26464c
---

 vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java      |    2 ++
 vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java |    3 +++
 2 files changed, 5 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
index 30c0acd..4ec1664 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryAdapter.java
@@ -311,6 +311,8 @@ public class DirectoryAdapter extends BaseAdapter {
     }
 
     public String getMediaLocation(int position) {
+        if (position >= mCurrentNode.children.size())
+            return null;
         return LibVLC.getExistingInstance().nativeToURI(
                 this.mCurrentDir + "/" + mCurrentNode.children.get(position).name
         );
diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
index ae50cbc..40960ae 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
@@ -100,6 +100,9 @@ public class DirectoryViewFragment extends SherlockListFragment implements ISort
 
         int id = item.getItemId();
         String mediaLocation = mDirectoryAdapter.getMediaLocation(info.position);
+        if (mediaLocation == null)
+            return super.onContextItemSelected(item);
+
         if(id == R.id.directory_view_play) {
             openMediaFile(info.position);
             return true;



More information about the Android mailing list