恢复应用程序

时间:2016-01-18 23:09:13

标签: java android exception nullpointerexception oncreateoptionsmenu

当应用程序在后台时,我得到一个空指针异常,并且当它被带到前台时必须再次创建主要活动。下面的代码用于重写活动方法onCreateOptionsMenu,其中我做了一些空检查,这应该导致应用程序在丢失数据的情况下使用SplashActivity重新启动。调试版本工作正常,但是当我构建发布版本时,我一直得到以下异常,当它停止显示有一个未知来源的菜单参数调用方法.ag()时将应用程序带到前台不明白。我不认为这是一个Proguard问题。

@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;
}

日志:

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)

0 个答案:

没有答案