{"record":{"id":"1937c5126b4f67e3","repo":"Blankj/AndroidUtilCode","slug":"no-menus","errorCode":null,"errorMessage":"no menus","messagePattern":"no menus","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/utildebug/src/main/java/com/blankj/utildebug/base/view/SwipeRightMenu.java","lineNumber":61,"sourceCode":"    public SwipeRightMenu(Context context) {\n        this(context, null);\n    }\n\n    public SwipeRightMenu(Context context, @Nullable AttributeSet attrs) {\n        super(context, attrs);\n        setOrientation(HORIZONTAL);\n        post(new Runnable() {\n            @Override\n            public void run() {\n                initView();\n            }\n        });\n    }\n\n    private void initView() {\n        int childCount = getChildCount();\n        if (childCount <= 1) {\n            throw new IllegalArgumentException(\"no menus\");\n        }\n        mContentView = getChildAt(0);\n\n        for (int i = 1; i < childCount; i++) {\n            MenuBean bean = new MenuBean(getChildAt(i));\n            mMenus.add(bean);\n            if (i == 1) {\n                bean.setCloseMargin(0);\n            } else {\n                bean.setCloseMargin(-mMenus.get(i - 2).getWidth());\n            }\n            mMenusWidth += bean.getWidth();\n        }\n        for (int i = 0; i < mMenus.size(); i++) {\n            mMenus.get(i).setOpenMargin(0);\n        }\n    }\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utildebug/src/main/java/com/blankj/utildebug/base/view/SwipeRightMenu.java#L43-L79","documentation":"SwipeRightMenu is a horizontal LinearLayout: the child at index 0 is the main content and every child at index >= 1 is a swipe-revealed menu action. initView() (scheduled via post(), so it runs after the view is attached) reads getChildCount() and throws IllegalArgumentException(\"no menus\") when it is <= 1, i.e. there is content but no menu children to reveal.","triggerScenarios":"Inflating or constructing SwipeRightMenu with only a single child view (the content) and no additional menu-action views; or adding the view programmatically with just one child so that getChildCount() == 1 when the posted initView() runs.","commonSituations":"Layout XML places only the content view inside <SwipeRightMenu> and forgets the menu buttons; menu items are added in code but after the post() runnable already fired; a copy of the custom view omits the menu children.","solutions":["Add at least one extra child view to SwipeRightMenu in XML (or before attach): index 0 is content, index 1+ are the menus, so getChildCount() must be >= 2.","If menus are added dynamically, add them before the view is attached/laid out so they exist when the posted initView() callback executes.","After setContentView/inflation, assert getChildCount() >= 2 to fail with a clearer message than the library's."],"exampleFix":"// before\n<com.blankj.utildebug.base.view.SwipeRightMenu\n    android:id=\"@+id/swipeMenu\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"wrap_content\">\n\n    <TextView\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        android:text=\"Content\" />\n    <!-- only content, no menu child -> throws \"no menus\" -->\n</com.blankj.utildebug.base.view.SwipeRightMenu>\n\n// after\n<com.blankj.utildebug.base.view.SwipeRightMenu ...>\n    <TextView ... android:text=\"Content\" />\n    <TextView ... android:text=\"Delete\" />   <!-- menu child at index 1 -->\n</com.blankj.utildebug.base.view.SwipeRightMenu>","handlingStrategy":"validation","validationCode":"ViewGroup menu = findViewById(R.id.swipeMenu);\nif (menu.getChildCount() < 2) {\n    throw new IllegalStateException(\n        \"SwipeRightMenu needs >=1 menu child besides content; found \"\n        + (menu.getChildCount() - 1));\n}","typeGuard":"private static boolean hasSwipeMenus(ViewGroup v) {\n    return v != null && v.getChildCount() > 1;\n}","tryCatchPattern":null,"preventionTips":["Always pair the content child with at least one menu-action child inside SwipeRightMenu.","When building the menu in code, add menu views before the view is attached so the post() callback sees them.","Treat getChildCount() < 2 as a programmer error in your own layout, not a runtime condition to swallow."],"tags":["android","view","layout","utildebug"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}