{"record":{"id":"e37fbe5fe9a4d6c5","repo":"material-components/material-components-android","slug":"maximum-number-of-items-supported-by-s-is-d-lim","errorCode":null,"errorMessage":"Maximum number of items supported by %s is %d. Limit can be checked with %s#getMaxItemCount()","messagePattern":"Maximum number of items supported by (.+?) is (.+?)\\. Limit can be checked with (.+?)#getMaxItemCount\\(\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/navigation/NavigationBarMenu.java","lineNumber":83,"sourceCode":"  @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 \"\n              + maxItemCount\n              + \". Limit can be checked with \"\n              + viewClassName\n              + \"#getMaxItemCount()\");\n    }\n    stopDispatchingItemsChanged();\n    final MenuItem item = super.addInternal(group, id, categoryOrder, title);\n    startDispatchingItemsChanged();\n    return item;\n  }\n}\n","sourceCodeStart":65,"sourceCodeEnd":98,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/navigation/NavigationBarMenu.java#L65-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nval items = listOf(\"A\", \"B\", \"C\", \"D\", \"E\", \"F\")\nitems.forEach { bottomNav.menu.add(it) }\n// after\nval items = listOf(\"A\", \"B\", \"C\", \"D\", \"E\", \"F\")\ncheck(items.size <= bottomNav.maxItemCount) { \"Too many bottom nav items\" }\nitems.take(bottomNav.maxItemCount).forEach { bottomNav.menu.add(it) }","handlingStrategy":"validation","validationCode":"fun safeAddItems(nav: NavigationBarView, items: List<MenuEntry>) {\n    val max = nav.maxItemCount // BottomNavigationView: 5\n    items.take(max).forEach { entry ->\n        nav.menu.add(0, entry.id, Menu.NONE, entry.title)\n    }\n}","typeGuard":null,"tryCatchPattern":"catch (e: IllegalArgumentException) { Log.e(TAG, \"Too many nav items; truncating\", e); rebuildMenuCapped() }","preventionTips":["Check maxItemCount before dynamic menu building","Design bottom navigation for 3-5 destinations per Material guidance","Route overflow destinations to a separate screen"],"tags":["android","material-components","navigation","menu","bottom-navigation","validation"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}