[Android] src: Prevent NullPointerException in DirectoryViewFragment. onContextItemSelected()

Edward Wang git at videolan.org
Fri Aug 3 04:14:46 CEST 2012


android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Thu Aug  2 22:13:01 2012 -0400| [3b3b3aeb3c1d6eba93052a53eba28f2bf41d8702] | committer: Edward Wang

src: Prevent NullPointerException in DirectoryViewFragment.onContextItemSelected()

AdapterContextMenuInfo can be null sometimes, according to the documentation.

Reference:
http://developer.android.com/reference/android/view/MenuItem.html#getMenuInfo%28%29

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

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

diff --git a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
index 51b953b..ae50cbc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DirectoryViewFragment.java
@@ -95,6 +95,9 @@ public class DirectoryViewFragment extends SherlockListFragment implements ISort
     @Override
     public boolean onContextItemSelected(MenuItem item) {
         AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
+        if(info == null) // info can be null
+            return super.onContextItemSelected(item);
+
         int id = item.getItemId();
         String mediaLocation = mDirectoryAdapter.getMediaLocation(info.position);
         if(id == R.id.directory_view_play) {



More information about the Android mailing list