J
J
JustAleksei2014-05-01 00:46:07
Android
JustAleksei, 2014-05-01 00:46:07

FATAL EXCEPTION inside onCreateOptionsMenu() on the inflater.inflate() line?

Hello!
Created a project using the Android Studio wizard using fragments and the Master-Detail markup template.
Added menu (text button without icon). On some phones / tablets, everything works well, but, for example, on the Nexus S emulator with android 4.1.2, when you start the Activity, an error immediately occurs:

E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.StackOverflowError
            at android.content.res.Resources.loadXmlResourceParser(Resources.java:2098)
            at android.content.res.Resources.getLayout(Resources.java:852)
            at android.view.MenuInflater.inflate(MenuInflater.java:107)
            at com.myApp.myApp2.ItemDetailFragment.onCreateOptionsMenu(ItemDetailFragment.java:128)
            at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:1582)
            at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1967)
            at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
            at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:393)
            at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:747)
            at android.app.Activity.invalidateOptionsMenu(Activity.java:2595)
            at android.support.v4.app.ActivityCompatHoneycomb.invalidateOptionsMenu(ActivityCompatHoneycomb.java:29)
            at android.support.v4.app.FragmentActivity.supportInvalidateOptionsMenu(FragmentActivity.java:648)
            at com. myApp.myApp2.ItemDetailFragment.onCreateOptionsMenu(ItemDetailFragment.java:137)
            at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:1582)
            at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1967)
            at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
            at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:393)
            at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:747)
            at android.app.Activity.invalidateOptionsMenu(Activity.java:2595)
            at android.support.v4.app.ActivityCompatHoneycomb.invalidateOptionsMenu(ActivityCompatHoneycomb.java:29)
            at android.support.v4.app.FragmentActivity.supportInvalidateOptionsMenu(FragmentActivity.java:648)
            at com.myApp.myApp2.ItemDetailFragment.onCreateOptionsMenu(ItemDetailFragment.java:137)
            at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:1582)
            at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1967)
            at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
            at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:393)
            at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:747)
            at android.app.Activity.invalidateOptionsMenu(Activity.java:2595)
            at android.support.v4.app.ActivityCompatHoneycomb.invalidateOptionsMenu(ActivityCompatHoneycomb.java:29)
            at android.support.v4.app.FragmentActivity.supportInvalidateOptionsMenu(FragmentActivity.java:648)
            at com.myApp.myApp2.ItemDetailFragment.onCreateOptionsMenu(ItemDetailFragment.java:137)
            at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:1582)
            at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1967)
            at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
            at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:393)
            at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:747)
            at android.app.Activity.invalidateOptionsMenu(Activity.java:2595)
            at android.support.v4.app.ActivityCompatHoneycomb.invalidateOptionsMenu(ActivityCompatHoneycomb.java:29)
            at android.support.v4.app.FragmentActivity.supportInvalidateOptionsMenu(FragmentActivity.java:648)
            at com.myApp.myApp2.ItemDetailFragment.onCreateOptionsMenu(ItemDetailFragment.java:137)
            at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:1582)
            at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:1967)
            at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:225)
            at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:393)
            at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:747)
            at android.app.Act

ItemDetailFragment.java - onCreateOptionsMenu()
@Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

        super.onCreateOptionsMenu(menu, inflater);

        menu.clear();
        inflater.inflate(R.menu.actions_item_detail, menu);

        //Показать/скрыть кнопку "Решение" в Action bar
        mMenu = menu.findItem(R.id.action_solution);

        //Установка соответствующего заголовка окна
        setSolutionMenuTitle();

        mMenu.setVisible(!Types.IS_EXAM_MODE || Types.CURRENT_EXAM_MODE == 2);
        getActivity().supportInvalidateOptionsMenu();
    }

R.menu.actions_item_detail
<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Solve, should appear as action button -->
    <item
        android:id="@+id/action_myAction"
        android:showAsAction="always|withText"
        android:title="Текст" />
</menu>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bimeg, 2014-05-01
@JustAleksei

This line creates a recursion.
getActivity().supportInvalidateOptionsMenu();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question