{"record":{"id":"dfb1e00bd4a1bffd","repo":"H07000223/FlycoTabLayout","slug":"tabentitys-can-not-be-null-or-empty","errorCode":null,"errorMessage":"TabEntitys can not be NULL or EMPTY !","messagePattern":"TabEntitys can not be NULL or EMPTY !","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java","lineNumber":196,"sourceCode":"        mTextBold = ta.getInt(R.styleable.CommonTabLayout_tl_textBold, TEXT_BOLD_NONE);\n        mTextAllCaps = ta.getBoolean(R.styleable.CommonTabLayout_tl_textAllCaps, false);\n\n        mIconVisible = ta.getBoolean(R.styleable.CommonTabLayout_tl_iconVisible, true);\n        mIconGravity = ta.getInt(R.styleable.CommonTabLayout_tl_iconGravity, Gravity.TOP);\n        mIconWidth = ta.getDimension(R.styleable.CommonTabLayout_tl_iconWidth, dp2px(0));\n        mIconHeight = ta.getDimension(R.styleable.CommonTabLayout_tl_iconHeight, dp2px(0));\n        mIconMargin = ta.getDimension(R.styleable.CommonTabLayout_tl_iconMargin, dp2px(2.5f));\n\n        mTabSpaceEqual = ta.getBoolean(R.styleable.CommonTabLayout_tl_tab_space_equal, true);\n        mTabWidth = ta.getDimension(R.styleable.CommonTabLayout_tl_tab_width, dp2px(-1));\n        mTabPadding = ta.getDimension(R.styleable.CommonTabLayout_tl_tab_padding, mTabSpaceEqual || mTabWidth > 0 ? dp2px(0) : dp2px(10));\n\n        ta.recycle();\n    }\n\n    public void setTabData(ArrayList<CustomTabEntity> tabEntitys) {\n        if (tabEntitys == null || tabEntitys.size() == 0) {\n            throw new IllegalStateException(\"TabEntitys can not be NULL or EMPTY !\");\n        }\n\n        this.mTabEntitys.clear();\n        this.mTabEntitys.addAll(tabEntitys);\n\n        notifyDataSetChanged();\n    }\n\n    /** 关联数据支持同时切换fragments */\n    public void setTabData(ArrayList<CustomTabEntity> tabEntitys, FragmentActivity fa, int containerViewId, ArrayList<Fragment> fragments) {\n        mFragmentChangeManager = new FragmentChangeManager(fa.getSupportFragmentManager(), containerViewId, fragments);\n        setTabData(tabEntitys);\n    }\n\n    /** 更新数据 */\n    public void notifyDataSetChanged() {\n        mTabsContainer.removeAllViews();\n        this.mTabCount = mTabEntitys.size();","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/H07000223/FlycoTabLayout/blob/528fcffe88d54eeafbc85ffd1ce375df043b3a28/FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java#L178-L214","documentation":"CommonTabLayout.setTabData() throws this IllegalStateException when the ArrayList<CustomTabEntity> passed in is null or has zero elements. The layout must have at least one tab to build its indicator and title views, so an empty entity list is treated as a programming error rather than silently rendering nothing.","triggerScenarios":"Calling setTabData(null), calling setTabData(new ArrayList<>()), or passing a list that was filtered/populated asynchronously and ended up empty before the call.","commonSituations":"Tab data fetched from a server/DB returned no rows; a variable declared but never initialized; a ViewModel/DAO result assigned after setTabData was already called; unit tests constructing the view without data.","solutions":["Pass a non-empty ArrayList<CustomTabEntity> with one entry per tab.","Guard the call site: only invoke setTabData after confirming list != null && !list.isEmpty().","If data loads asynchronously, call setTabData inside the load callback once items are available.","Wrap the call in try-catch for IllegalStateException if empty data is an expected, recoverable condition."],"exampleFix":"// before\nlayout.setTabData(mTabEntitys);\n// after\nif (mTabEntitys != null && !mTabEntitys.isEmpty()) {\n    layout.setTabData(mTabEntitys);\n}","handlingStrategy":"validation","validationCode":"if (tabEntitys != null && !tabEntitys.isEmpty()) {\n    commonTabLayout.setTabData(tabEntitys);\n}","typeGuard":"boolean isValidTabData(ArrayList<CustomTabEntity> list) {\n    return list != null && !list.isEmpty();\n}","tryCatchPattern":"try {\n    commonTabLayout.setTabData(tabEntitys);\n} catch (IllegalStateException e) {\n    Log.e(\"TabLayout\", \"No tab entities provided\", e);\n}","preventionTips":["Always initialize tab entity lists before view binding.","Populate tab data in the async load callback, not before.","Use a helper method that centralizes the non-empty check.","In tests, assert list non-empty before constructing the layout."],"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"}