material-components/material-components-android · error · UnsupportedOperationException
%s does not support submenus
Error message
%s does not support submenus
What it means
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.
Source
Thrown at lib/java/com/google/android/material/navigation/NavigationBarMenu.java:68
@NonNull Class<?> viewClass,
int maxItemCount,
boolean subMenuSupported) {
super(context);
this.viewClass = viewClass;
this.maxItemCount = maxItemCount;
this.subMenuSupported = subMenuSupported;
}
/** Returns the maximum number of items that can be shown in NavigationBarMenu. */
public int getMaxItemCount() {
return maxItemCount;
}
@NonNull
@Override
public SubMenu addSubMenu(int group, int id, int categoryOrder, @NonNull CharSequence title) {
if (!subMenuSupported) {
throw new UnsupportedOperationException(
viewClass.getSimpleName() + " does not support submenus");
}
final MenuItemImpl item = (MenuItemImpl) addInternal(group, id, categoryOrder, title);
final SubMenuBuilder subMenu = new NavigationBarSubMenu(getContext(), this, item);
item.setSubMenu(subMenu);
return subMenu;
}
@Override
@NonNull
protected MenuItem addInternal(
int group, int id, int categoryOrder, @NonNull CharSequence title) {
if (size() + 1 > maxItemCount) {
String viewClassName = viewClass.getSimpleName();
throw new IllegalArgumentException(
"Maximum number of items supported by "
+ viewClassName
+ " is "View on GitHub (pinned to ac7e18efee)
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
Example fix
<!-- before: menu_bottom.xml used by BottomNavigationView -->
<item android:id="@+id/nav_more" android:title="More">
<menu>
<item android:id="@+id/nav_settings" android:title="Settings"/>
</menu>
</item>
<!-- after -->
<item android:id="@+id/nav_settings" android:title="Settings"/> Defensive patterns
Strategy: validation
Validate before calling
// Strip submenu declarations before inflating into a view that rejects them
fun canHaveSubmenus(view: NavigationBarView): Boolean =
view.menu is NavigationBarMenu && (view.menu as NavigationBarMenu).let { /* consult API level docs */ true } // simplest: don't nest menus in bottom nav at all Try / catch
catch (e: UnsupportedOperationException) { Log.w(TAG, "View does not support submenus; using flat menu", e); inflateFlatMenu() } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Sharing one menu XML between NavigationView (drawer, submenus OK) and BottomNavigationView (submenus rejected); copy-pasting drawer menu layouts into bottom navigation.
Related errors
- Maximum number of items supported by %s is %d. Limit can be
- Only one layer of submenu is supported; a submenu inside a s
- %d is not a valid view id
- Called setCheckedItem(MenuItem) with an item that is not in
- secondaryIconGravity cannot have the same alignment as iconG
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/66059850e2834043.
Report an issue: GitHub.