I am getting a null pointer exception when the app has been in the background and has to create the main activity again when brought to the foreground. The code below is for the overridden activity method onCreateOptionsMenu where I do a few null checks which should cause the app to restart with the SplashActivity in case of lost data. The debug build works fine but when I build the release version I consistently get the exception below after bringing the app to the foreground when it has been stopped showing that there is an Unknown Source for the menu parameter calling a method .a.g() which I do not understand. I don't think it is a Proguard issue.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (agencyManager == null || menu == null || getMenuInflater() == null) {
// If agencyManager data lost (possibly caused by backgrounding the app for a long period of time),
// launch the splash activity, pass through any potential stop selected
// from a notification, and finish.
Intent intent = new Intent(MapActivity.this, SplashActivity.class);
if (stopSelectedFromNotification != -1) {
intent.putExtra(STOP_ID_EXTRA, stopSelectedFromNotification);
intent.putExtra(ROUTE_ID_EXTRA, routeSelectedFromNotification);
}
startActivity(intent);
overridePendingTransition(0, 0); // Don't animate the transition
finish();
return false;
}
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
MenuItem twitter = menu.findItem(R.id.action_news);
twitter.setVisible(!agencyManager.getTwitter().equals(""));
MenuItem website = menu.findItem(R.id.action_website);
website.setVisible(!agencyManager.getURL().equals(""));
MenuItem faq = menu.findItem(R.id.action_faq);
faq.setVisible(!agencyManager.getFaqURL().equals(""));
MenuItem riding = menu.findItem(R.id.action_riding);
riding.setVisible(!agencyManager.getRidingURL().equals(""));
MenuItem code = menu.findItem(R.id.action_code);
code.setVisible(!agencyManager.getCodeURL().equals(""));
MenuItem fares = menu.findItem(R.id.action_fares);
fares.setVisible(agencyManager.getFareJSON().length()>5 || agencyManager.getFareText().length()>5);
/**
//Webschedule view option added to menu, will be visible if schedule table supported
MenuItem webSchedule = menu.findItem(R.id.action_web_schedule);
final Route route = mapUiManager.selectedRoute;
webSchedule.setVisible(agencyManager.useScheduleTable());
**/
MenuItem settings = menu.findItem(R.id.action_settings);
// Display the welcome info screens the first time the app is run
displayWelcomeInfoFirstRun();
return true;
}
Log:
01-18 12:48:28.872 31937-31937/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: edu.company.android.packagename, PID: 31937
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String edu.company.android.packagename.a.g()' on a null object reference
at edu.company.android.packagename.MapActivity.onCreateOptionsMenu(Unknown Source)
at android.app.Activity.onCreatePanelMenu(Activity.java:2850)
at android.support.v4.app.aa.onCreatePanelMenu(Unknown Source)
at android.support.v7.a.f.a(Unknown Source)
at android.support.v7.a.l.a(Unknown Source)
at android.support.v7.a.f.onCreatePanelMenu(Unknown Source)
at android.support.v7.a.m.onCreatePanelMenu(Unknown Source)
at com.android.internal.policy.PhoneWindow.preparePanel(PhoneWindow.java:567)
at com.android.internal.policy.PhoneWindow.doInvalidatePanelMenu(PhoneWindow.java:939)
at com.android.internal.policy.PhoneWindow$1.run(PhoneWindow.java:271)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)