{"record":{"id":"e87c171d78a5fafc","repo":"material-components/material-components-android","slug":"only-one-layer-of-submenu-is-supported-a-submenu","errorCode":null,"errorMessage":"Only one layer of submenu is supported; a submenu inside a submenu is not supported by the Navigation Bar.","messagePattern":"Only one layer of submenu is supported; a submenu inside a submenu is not supported by the Navigation Bar\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/navigation/NavigationBarMenuView.java","lineNumber":1226,"sourceCode":"    int menuSize = menu.size();\n    buttons = new NavigationBarMenuItemView[menuSize];\n    int collapsedItemsSoFar = 0;\n    int nextSubheaderItemCount = 0;\n    boolean shifting =\n        isShifting(labelVisibilityMode, getCurrentVisibleContentItemCount());\n    for (int i = 0; i < menuSize; i++) {\n      MenuItem menuItem = menu.getItemAt(i);\n      NavigationBarMenuItemView child;\n      if (menuItem instanceof DividerMenuItem) {\n        // Add a divider\n        child = new NavigationBarDividerView(getContext());\n        child.setOnlyShowWhenExpanded(true);\n        ((NavigationBarDividerView) child).setDividersEnabled(dividersEnabled);\n      } else if (menuItem.hasSubMenu()) {\n        if (nextSubheaderItemCount > 0) {\n          // We do not support submenus inside submenus. If there is still subheader items to be\n          // instantiated, we should not have another submenu.\n          throw new IllegalArgumentException(\n              \"Only one layer of submenu is supported; a submenu \"\n                  + \"inside a submenu is not supported by the Navigation Bar.\");\n        }\n        // Add subheader item\n        child = new NavigationBarSubheaderView(getContext());\n        ((NavigationBarSubheaderView) child).\n            setTextAppearance(horizontalItemTextAppearanceActive != 0\n                ? horizontalItemTextAppearanceActive : itemTextAppearanceActive);\n        ((NavigationBarSubheaderView) child).setTextColor(itemTextColorFromUser);\n        child.setOnlyShowWhenExpanded(true);\n        child.initialize((MenuItemImpl) menuItem, 0);\n        nextSubheaderItemCount = menuItem.getSubMenu().size();\n      } else if (nextSubheaderItemCount > 0) { // Add submenu items\n        child =\n            createMenuItem(i, (MenuItemImpl) menuItem, shifting, /* hideWhenCollapsed= */ true);\n        nextSubheaderItemCount--;\n      } else {\n        child =","sourceCodeStart":1208,"sourceCodeEnd":1244,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/navigation/NavigationBarMenuView.java#L1208-L1244","documentation":"While building item views from the menu, NavigationBarMenuView throws IllegalArgumentException if it encounters a submenu item while still expecting subheader children from a previous submenu — i.e. nested submenus. The expanded navigation bar supports exactly one layer of submenu; a submenu declared inside another submenu's items is rejected at layout time.","triggerScenarios":"A menu XML applied to a navigation bar with submenu support enabled where an <item> inside a nested <menu> itself contains another <menu>; the loop sees menuItem.hasSubMenu() while nextSubheaderItemCount > 0 and throws.","commonSituations":"Deeply nested drawer-style menus reused in NavigationBarView with expanded menu support; menu files authored for NavigationView with two-level nesting.","solutions":["Flatten the menu so submenus contain only plain items (one nesting level total)","Move deeper navigation into dedicated screens reached by selecting a submenu item","Lint-check menu XMLs for <menu> nested more than one level deep when used with navigation bars"],"exampleFix":"<!-- before -->\n<item android:title=\"Section\">\n  <menu>\n    <item android:title=\"Sub\" >\n      <menu><item android:title=\"Deep\"/></menu>\n    </item>\n  </menu>\n</item>\n<!-- after -->\n<item android:title=\"Section\">\n  <menu>\n    <item android:title=\"Sub\"/>\n    <item android:title=\"Deep\"/>\n  </menu>\n</item>","handlingStrategy":"validation","validationCode":"// Static check: reject menu XMLs with two-level nesting\nfun maxMenuDepth(parser: XmlPullParser): Int {\n    var depth = 0; var max = 0\n    while (parser.next() != XmlPullParser.END_DOCUMENT) {\n        if (parser.eventType == XmlPullParser.START_TAG && parser.name == \"menu\") max = maxOf(max, ++depth)\n        if (parser.eventType == XmlPullParser.END_TAG && parser.name == \"menu\") depth--\n    }\n    return max\n}","typeGuard":null,"tryCatchPattern":"catch (e: IllegalArgumentException) { Log.e(TAG, \"Nested submenus unsupported; flattening menu\", e); inflateFlatMenu() }","preventionTips":["Limit navigation bar menus to one submenu layer","Move deeper hierarchy into content screens","Automate a menu-depth check in CI"],"tags":["android","material-components","navigation","menu","submenu"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}