{"record":{"id":"ebfadd2b7f5362d9","repo":"H07000223/FlycoTabLayout","slug":"titles-can-not-be-null-or-empty","errorCode":null,"errorMessage":"Titles can not be NULL or EMPTY !","messagePattern":"Titles can not be NULL or EMPTY !","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SegmentTabLayout.java","lineNumber":166,"sourceCode":"        mTextSelectColor = ta.getColor(R.styleable.SegmentTabLayout_tl_textSelectColor, Color.parseColor(\"#ffffff\"));\n        mTextUnselectColor = ta.getColor(R.styleable.SegmentTabLayout_tl_textUnselectColor, mIndicatorColor);\n        mTextBold = ta.getInt(R.styleable.SegmentTabLayout_tl_textBold, TEXT_BOLD_NONE);\n        mTextAllCaps = ta.getBoolean(R.styleable.SegmentTabLayout_tl_textAllCaps, false);\n\n        mTabSpaceEqual = ta.getBoolean(R.styleable.SegmentTabLayout_tl_tab_space_equal, true);\n        mTabWidth = ta.getDimension(R.styleable.SegmentTabLayout_tl_tab_width, dp2px(-1));\n        mTabPadding = ta.getDimension(R.styleable.SegmentTabLayout_tl_tab_padding, mTabSpaceEqual || mTabWidth > 0 ? dp2px(0) : dp2px(10));\n\n        mBarColor = ta.getColor(R.styleable.SegmentTabLayout_tl_bar_color, Color.TRANSPARENT);\n        mBarStrokeColor = ta.getColor(R.styleable.SegmentTabLayout_tl_bar_stroke_color, mIndicatorColor);\n        mBarStrokeWidth = ta.getDimension(R.styleable.SegmentTabLayout_tl_bar_stroke_width, dp2px(1));\n\n        ta.recycle();\n    }\n\n    public void setTabData(String[] titles) {\n        if (titles == null || titles.length == 0) {\n            throw new IllegalStateException(\"Titles can not be NULL or EMPTY !\");\n        }\n\n        this.mTitles = titles;\n\n        notifyDataSetChanged();\n    }\n\n    /** 关联数据支持同时切换fragments */\n    public void setTabData(String[] titles, FragmentActivity fa, int containerViewId, ArrayList<Fragment> fragments) {\n        mFragmentChangeManager = new FragmentChangeManager(fa.getSupportFragmentManager(), containerViewId, fragments);\n        setTabData(titles);\n    }\n\n    /** 更新数据 */\n    public void notifyDataSetChanged() {\n        mTabsContainer.removeAllViews();\n        this.mTabCount = mTitles.length;\n        View tabView;","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/H07000223/FlycoTabLayout/blob/528fcffe88d54eeafbc85ffd1ce375df043b3a28/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SegmentTabLayout.java#L148-L184","documentation":"SegmentTabLayout.setTabData(String[] titles) throws this IllegalStateException when the titles array is null or zero-length. The segmented control draws one segment per title, so an empty array would produce no usable UI and the library fails fast instead.","triggerScenarios":"Passing a null String[] to setTabData, or passing titles = new String[0]; also passing an array built from an empty resource/collection.","commonSituations":"Hardcoding an empty array placeholder and forgetting to fill it; loading titles from strings.xml or server config that resolved to nothing; refactoring removed the titles but kept the call.","solutions":["Pass a String[] with at least one title, one per segment.","Validate before calling: if (titles != null && titles.length > 0) before setTabData.","If titles come from remote/config, supply defaults or skip rendering the layout until data arrives.","Catch IllegalStateException around the call when emptiness is an expected runtime condition."],"exampleFix":"// before\nsegmentTabLayout.setTabData(titles);\n// after\nif (titles != null && titles.length > 0) {\n    segmentTabLayout.setTabData(titles);\n}","handlingStrategy":"validation","validationCode":"if (titles != null && titles.length > 0) {\n    segmentTabLayout.setTabData(titles);\n}","typeGuard":"boolean isValidTitles(String[] titles) {\n    return titles != null && titles.length > 0;\n}","tryCatchPattern":"try {\n    segmentTabLayout.setTabData(titles);\n} catch (IllegalStateException e) {\n    Log.e(\"SegmentTabLayout\", \"titles null/empty\", e);\n}","preventionTips":["Define title arrays as constants or string resources so they are never null.","Check array length right after loading titles from config/server.","Avoid passing placeholder empty arrays during scaffolding.","Keep titles and segment count in sync in one source of truth."],"tags":["android","tablayout","illegal-state","validation"],"backgroundTag":"empty-required-field","analyzedSha":"528fcffe88d54eeafbc85ffd1ce375df043b3a28","analyzedAt":"2026-09-08T23:52:16.457Z","contentChangedAt":"2026-09-08T23:52:16.457Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}