{"record":{"id":"5508fa156786c008","repo":"Tencent/QMUI_Android","slug":"index-must-greater-than-0","errorCode":null,"errorMessage":"index must greater than 0","messagePattern":"index must greater than 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"qmui/src/main/java/com/qmuiteam/qmui/skin/QMUISkinManager.java","lineNumber":244,"sourceCode":"        if (skinItem != null) {\n            return skinItem.getTheme();\n        }\n        return null;\n    }\n\n    @Nullable\n    public Resources.Theme getCurrentTheme() {\n        SkinItem skinItem = mSkins.get(mCurrentSkin);\n        if (skinItem != null) {\n            return skinItem.getTheme();\n        }\n        return null;\n    }\n\n    @MainThread\n    public void addSkin(int index, int styleRes) {\n        if (index <= 0) {\n            throw new IllegalArgumentException(\"index must greater than 0\");\n        }\n        SkinItem skinItem = mSkins.get(index);\n        if (skinItem != null) {\n            if (skinItem.getStyleRes() == styleRes) {\n                return;\n            }\n            throw new RuntimeException(\"already exist the theme item for \" + index);\n        }\n        skinItem = new SkinItem(styleRes);\n        mSkins.append(index, skinItem);\n    }\n\n    static ViewSkinCurrent getViewSkinCurrent(View view) {\n        Object current = view.getTag(R.id.qmui_skin_current);\n        if (current instanceof ViewSkinCurrent) {\n            return (ViewSkinCurrent) current;\n        }\n        return null;","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/qmui/src/main/java/com/qmuiteam/qmui/skin/QMUISkinManager.java#L226-L262","documentation":"QMUISkinManager.addSkin(index, styleRes) requires the skin index to be strictly positive; index 0 is reserved (DEFAULT_SKIN) and negative indices are invalid. Passing index <= 0 is rejected with an IllegalArgumentException before the skin is stored.","triggerScenarios":"Calling addSkin(0, R.style.SkinX) or addSkin(-1, ...) directly, or building a loop that starts at 0 when registering skins after install().","commonSituations":"Misunderstanding that index 0 means 'default skin' and trying to register the default theme; generating skin indices from an array position starting at 0.","solutions":["Use indices starting at 1 for custom skins.","To customize the default skin, use the style/theme mechanism for DEFAULT_SKIN instead of addSkin(0, ...).","Fix loops to iterate from 1, or add 1 to array-based indices."],"exampleFix":"// before\nskinManager.addSkin(0, R.style.AppSkin_Blue); // throws\n\n// after\nskinManager.addSkin(1, R.style.AppSkin_Blue);","handlingStrategy":"validation","validationCode":"if (index > 0) {\n    skinManager.addSkin(index, styleRes);\n}","typeGuard":"boolean isSkinIndexValid(int index) {\n    return index > 0;\n}","tryCatchPattern":"try {\n    skinManager.addSkin(index, styleRes);\n} catch (IllegalArgumentException e) {\n    Log.w(TAG, \"invalid skin index: \" + index, e);\n}","preventionTips":["Start custom skin indices at 1","Never attempt to register index 0 (DEFAULT_SKIN is implicit)","Derive indices from constants, not array positions starting at 0"],"tags":["android","qmui","skin","argument-out-of-range"],"backgroundTag":"value-out-of-range","analyzedSha":"026e7d486677d6593a96689cd590ec3561176717","analyzedAt":"2026-09-06T13:32:24.816Z","contentChangedAt":"2026-09-06T13:32:24.816Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}