NullPointerException and NumberFormatException

This commit is contained in:
Caesar2011
2019-02-07 22:47:51 +01:00
parent 0776447d3b
commit 041c46284b
2 changed files with 22 additions and 16 deletions

View File

@@ -500,15 +500,19 @@ public class MainActivity extends AppCompatActivity
case FRAGMENT_CANTEENS_DETAILS: case FRAGMENT_CANTEENS_DETAILS:
getCanteenBrowser().getCanteens(success -> { getCanteenBrowser().getCanteens(success -> {
int size = mNavigationView.getMenu().size(); int size = mNavigationView.getMenu().size();
Canteen canteen = success.getCanteen(Integer.parseInt(mFragmentData)); try {
//noinspection ConstantConditions Canteen canteen = success.getCanteen(Integer.parseInt(mFragmentData));
String title = canteen == null ? null : canteen.getName(); //noinspection ConstantConditions
for (int k = 0; k < size; k++) { String title = canteen == null ? null : canteen.getName();
MenuItem menuItem = mNavigationView.getMenu().getItem(k); for (int k = 0; k < size; k++) {
if (menuItem.getTitle().equals(title)) { MenuItem menuItem = mNavigationView.getMenu().getItem(k);
menuItem.setChecked(true); if (menuItem.getTitle().equals(title)) {
break; menuItem.setChecked(true);
break;
}
} }
} catch (NumberFormatException e) {
e.printStackTrace();
} }
}, log::e); }, log::e);
return; return;

View File

@@ -53,14 +53,16 @@ public class PrefsFragment extends PreferenceFragmentCompat implements SharedPre
if (getActivity() != null && getActivity() instanceof MainActivity) { if (getActivity() != null && getActivity() instanceof MainActivity) {
CustomAccountManager accountManager = ((MainActivity) getActivity()).getAccountManager(); CustomAccountManager accountManager = ((MainActivity) getActivity()).getAccountManager();
Account accountByType = accountManager.getAccountByType(AccountGeneral.ACCOUNT_TYPE); if (accountManager != null) {
if (accountByType != null) { Account accountByType = accountManager.getAccountByType(AccountGeneral.ACCOUNT_TYPE);
ContentResolver.setSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME, true); if (accountByType != null) {
ContentResolver.addPeriodicSync( ContentResolver.setSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME, true);
accountByType, ContentResolver.addPeriodicSync(
KVVContentProvider.PROVIDER_NAME, accountByType,
Bundle.EMPTY, KVVContentProvider.PROVIDER_NAME,
Long.parseLong(Preferences.getStringArray(getActivity(), R.array.pref_sync_frequency))); Bundle.EMPTY,
Long.parseLong(Preferences.getStringArray(getActivity(), R.array.pref_sync_frequency)));
}
} }
} }
} }