@JustAleksei

FATAL EXCEPTION внутри onCreateOptionsMenu() на строке inflater.inflate()?

Здравствуйте!

Создал проект с помощью визарда Android Studio с использованием фрагментов и шаблона разметки Master-Detail.

Добавил меню (текстовая кнопка без иконки). На части телефонов\планшетов все работает хорошо, но, например, на эмуляторе Nexus S с android 4.1.2 при запуске Activity сразу идет ошибка:

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>
  • Вопрос задан
  • 3755 просмотров
Решения вопроса 1
@bimeg
Эта строчка порождает рекурсию.

getActivity().supportInvalidateOptionsMenu();
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы