From 91fb7e6c2a3224b6fe643a3f22978b4b8badfeca Mon Sep 17 00:00:00 2001 From: Tom Hennen Date: Fri, 17 Apr 2015 17:29:00 -0400 Subject: [PATCH] Fixed some NullPointerExceptions These were happening on some handsets when onPrepareOptionsMenu was getting called. It is sometimes called before the menu is actually loaded, causing us to not find the MenuItem we're looking for. This solves the symptom, if not the cause. After making this change the number of failures reported on Apkudo dropped from 20 devices to just 6. --- .../de/danoeh/antennapod/fragment/AllEpisodesFragment.java | 5 ++++- .../danoeh/antennapod/fragment/PlaybackHistoryFragment.java | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java index 58b6f734f..2eef7b635 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -219,7 +219,10 @@ public class AllEpisodesFragment extends Fragment { public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); if (itemsLoaded && !MenuItemUtils.isActivityDrawerOpen((NavDrawerActivity) getActivity())) { - menu.findItem(R.id.mark_all_read_item).setVisible(unreadItems != null && !unreadItems.isEmpty()); + MenuItem menuItem = menu.findItem(R.id.mark_all_read_item); + if (menuItem != null) { + menuItem.setVisible(unreadItems != null && !unreadItems.isEmpty()); + } } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java index ab38af106..9002227d6 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -146,7 +146,10 @@ public class PlaybackHistoryFragment extends ListFragment { public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); if (itemsLoaded && !MenuItemUtils.isActivityDrawerOpen((NavDrawerActivity) getActivity())) { - menu.findItem(R.id.clear_history_item).setVisible(playbackHistory != null && !playbackHistory.isEmpty()); + MenuItem menuItem = menu.findItem(R.id.clear_history_item); + if (menuItem != null) { + menuItem.setVisible(playbackHistory != null && !playbackHistory.isEmpty()); + } } }