{"record":{"id":"f6ff1c576c2951cc","repo":"Tencent/QMUI_Android","slug":"already-exist-the-theme-item-for","errorCode":null,"errorMessage":"already exist the theme item for ","messagePattern":"already exist the theme item for ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"qmui/src/main/java/com/qmuiteam/qmui/skin/QMUISkinManager.java","lineNumber":251,"sourceCode":"    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;\n    }\n\n    public void dispatch(View view, int skinIndex) {\n        if (view == null) {\n            return;\n        }\n        if (QMUIConfig.DEBUG) {","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/qmui/src/main/java/com/qmuiteam/qmui/skin/QMUISkinManager.java#L233-L269","documentation":"QMUISkinManager.addSkin() throws when a skin is already registered for the same non-default index with a DIFFERENT style resource. Registering the identical style for the same index silently returns, but changing the style under an existing index is rejected to prevent silently redefining themes.","triggerScenarios":"Calling addSkin(index, styleRes) twice for the same index with different styleRes values, e.g. rebuilding the skin table on every Activity start or after calling install() again.","commonSituations":"Re-running skin registration code in onCreate/onResume without an idempotency check; refactoring renamed a skin style so the old index now maps to a new style; two modules each register skins into shared index numbers.","solutions":["Register each skin index exactly once (guard with a boolean or check during initialization).","Call removeSkin(index) before re-registering an index with a different style.","Make style resources stable per index — do not swap styles under an existing index.","Use distinct increasing indices for new skins instead of reusing indices."],"exampleFix":"// before\nskinManager.addSkin(1, R.style.Skin_Blue);\nskinManager.addSkin(1, R.style.Skin_Dark); // throws\n\n// after\nskinManager.removeSkin(1);\nskinManager.addSkin(1, R.style.Skin_Dark);","handlingStrategy":"validation","validationCode":"if (skinIndexOf(styleRes) != index || isFirstRegistration) {\n    skinManager.addSkin(index, styleRes);\n}","typeGuard":null,"tryCatchPattern":"try {\n    skinManager.addSkin(index, styleRes);\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"already exist\")) {\n        skinManager.removeSkin(index);\n        skinManager.addSkin(index, styleRes);\n    } else throw e;\n}","preventionTips":["Register skins once, at app/library init, idempotently","Never change the style resource mapped to an existing index","Call removeSkin before re-registering a modified index","Use a central skin registry class instead of scattered addSkin calls"],"tags":["android","qmui","skin","duplicate-key","conflict"],"backgroundTag":"file-already-exists","analyzedSha":"026e7d486677d6593a96689cd590ec3561176717","analyzedAt":"2026-09-06T13:32:24.816Z","contentChangedAt":"2026-09-06T13:32:24.816Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}