{"record":{"id":"66059850e2834043","repo":"material-components/material-components-android","slug":"s-does-not-support-submenus","errorCode":null,"errorMessage":"%s does not support submenus","messagePattern":"(.+?) does not support submenus","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/navigation/NavigationBarMenu.java","lineNumber":68,"sourceCode":"      @NonNull Class<?> viewClass,\n      int maxItemCount,\n      boolean subMenuSupported) {\n    super(context);\n    this.viewClass = viewClass;\n    this.maxItemCount = maxItemCount;\n    this.subMenuSupported = subMenuSupported;\n  }\n\n  /** Returns the maximum number of items that can be shown in NavigationBarMenu. */\n  public int getMaxItemCount() {\n    return maxItemCount;\n  }\n\n  @NonNull\n  @Override\n  public SubMenu addSubMenu(int group, int id, int categoryOrder, @NonNull CharSequence title) {\n    if (!subMenuSupported) {\n      throw new UnsupportedOperationException(\n          viewClass.getSimpleName() + \" does not support submenus\");\n    }\n    final MenuItemImpl item = (MenuItemImpl) addInternal(group, id, categoryOrder, title);\n    final SubMenuBuilder subMenu = new NavigationBarSubMenu(getContext(), this, item);\n    item.setSubMenu(subMenu);\n    return subMenu;\n  }\n\n  @Override\n  @NonNull\n  protected MenuItem addInternal(\n      int group, int id, int categoryOrder, @NonNull CharSequence title) {\n    if (size() + 1 > maxItemCount) {\n      String viewClassName = viewClass.getSimpleName();\n      throw new IllegalArgumentException(\n          \"Maximum number of items supported by \"\n              + viewClassName\n              + \" is \"","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/navigation/NavigationBarMenu.java#L50-L86","documentation":"NavigationBarMenu.addSubMenu throws UnsupportedOperationException when the navigation bar was constructed without submenu support (subMenuSupported=false). BottomNavigationView and NavigationBarView historically disallow submenus because their item layout has no way to render nested menus; only specific configurations (e.g. NavigationBarView with expanded selections) enable it.","triggerScenarios":"Inflating a menu XML that contains a <menu> nested inside an <item> and applying it to a BottomNavigationView/NavigationBarView constructed with subMenuSupported=false; or calling getMenu().addSubMenu(...) programmatically on such a view.","commonSituations":"Sharing one menu XML between NavigationView (drawer, submenus OK) and BottomNavigationView (submenus rejected); copy-pasting drawer menu layouts into bottom navigation.","solutions":["Remove nested <menu> elements from the menu XML used with BottomNavigationView/NavigationBarView","Use a separate simplified menu resource for bottom navigation with only top-level <item> entries","If drill-down navigation is needed, navigate to a new screen/fragment instead of using a submenu"],"exampleFix":"<!-- before: menu_bottom.xml used by BottomNavigationView -->\n<item android:id=\"@+id/nav_more\" android:title=\"More\">\n  <menu>\n    <item android:id=\"@+id/nav_settings\" android:title=\"Settings\"/>\n  </menu>\n</item>\n<!-- after -->\n<item android:id=\"@+id/nav_settings\" android:title=\"Settings\"/>","handlingStrategy":"validation","validationCode":"// Strip submenu declarations before inflating into a view that rejects them\nfun canHaveSubmenus(view: NavigationBarView): Boolean =\n    view.menu is NavigationBarMenu && (view.menu as NavigationBarMenu).let { /* consult API level docs */ true } // simplest: don't nest menus in bottom nav at all","typeGuard":null,"tryCatchPattern":"catch (e: UnsupportedOperationException) { Log.w(TAG, \"View does not support submenus; using flat menu\", e); inflateFlatMenu() }","preventionTips":["Keep bottom navigation menus flat (top-level items only)","Use separate menu XML files per navigation surface","Review menu XMLs for nested <menu> elements during code review"],"tags":["android","material-components","navigation","menu","bottom-navigation"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}