From e2d272e905c0350af19a773c80a29270cde3e5d4 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 20 Mar 2015 19:56:55 -0700 Subject: Add try/catch blocks to create options menu in case called before context is valid --- src/github/daneren2005/dsub/activity/SubsonicActivity.java | 6 +++++- src/github/daneren2005/dsub/fragments/MainFragment.java | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index e3094546..d5821dac 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -348,7 +348,11 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(drawerOpen) { menuInflater.inflate(R.menu.drawer_menu, menu); } else if(currentFragment != null) { - currentFragment.onCreateOptionsMenu(menu, menuInflater); + try { + currentFragment.onCreateOptionsMenu(menu, menuInflater); + } catch(Exception e) { + Log.w(TAG, "Error on creating options menu", e); + } } return true; } diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java index 7225f551..fb36c9e3 100644 --- a/src/github/daneren2005/dsub/fragments/MainFragment.java +++ b/src/github/daneren2005/dsub/fragments/MainFragment.java @@ -78,8 +78,12 @@ public class MainFragment extends SubsonicFragment { public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) { menuInflater.inflate(R.menu.main, menu); - if(!ServerInfo.isMadsonic(context) || !UserUtil.isCurrentAdmin()) { - menu.setGroupVisible(R.id.madsonic, false); + try { + if (!ServerInfo.isMadsonic(context) || !UserUtil.isCurrentAdmin()) { + menu.setGroupVisible(R.id.madsonic, false); + } + } catch(Exception e) { + Log.w(TAG, "Error on setting madsonic invisible", e); } } -- cgit v1.2.3