material-components/material-components-android · error · IllegalArgumentException
Maximum number of items supported by %s is %d. Limit can be
Error message
Maximum number of items supported by %s is %d. Limit can be checked with %s#getMaxItemCount()
What it means
NavigationBarMenu.addInternal enforces maxItemCount (5 for BottomNavigationView per Material spec) and throws IllegalArgumentException when adding one more item would exceed it. The message names the view class, the limit, and points to getMaxItemCount() so callers can check programmatically.
Source
Thrown at lib/java/com/google/android/material/navigation/NavigationBarMenu.java:83
@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 "
+ maxItemCount
+ ". Limit can be checked with "
+ viewClassName
+ "#getMaxItemCount()");
}
stopDispatchingItemsChanged();
final MenuItem item = super.addInternal(group, id, categoryOrder, title);
startDispatchingItemsChanged();
return item;
}
}
View on GitHub (pinned to ac7e18efee)
Solutions
- Reduce menu items to at most view.getMaxItemCount() (5 by default)
- Move overflow items into a 'More' sheet/dialog or the app's primary navigation elsewhere
- When building the menu dynamically, truncate or validate the source list before adding
Example fix
// before
val items = listOf("A", "B", "C", "D", "E", "F")
items.forEach { bottomNav.menu.add(it) }
// after
val items = listOf("A", "B", "C", "D", "E", "F")
check(items.size <= bottomNav.maxItemCount) { "Too many bottom nav items" }
items.take(bottomNav.maxItemCount).forEach { bottomNav.menu.add(it) } Defensive patterns
Strategy: validation
Validate before calling
fun safeAddItems(nav: NavigationBarView, items: List<MenuEntry>) {
val max = nav.maxItemCount // BottomNavigationView: 5
items.take(max).forEach { entry ->
nav.menu.add(0, entry.id, Menu.NONE, entry.title)
}
} Try / catch
catch (e: IllegalArgumentException) { Log.e(TAG, "Too many nav items; truncating", e); rebuildMenuCapped() } Prevention
- Check maxItemCount before dynamic menu building
- Design bottom navigation for 3-5 destinations per Material guidance
- Route overflow destinations to a separate screen
When it happens
Trigger: Inflating or programmatically adding more than getMaxItemCount() items (typically 5) to a BottomNavigationView/NavigationBarView menu; e.g. a menu XML with 6 top-level <item> entries.
Common situations: Product adds a sixth tab; dynamically building the menu from a data-driven list without capping; reusing a drawer menu with many items in bottom navigation.
Related errors
- %s does not support submenus
- 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
- There must be a keyline marked as focal.
AI-assisted analysis of material-components/material-components-android@ac7e18efee (2026-08-14).
Data as JSON: /api/errors/e37fbe5fe9a4d6c5.
Report an issue: GitHub.