H07000223/FlycoTabLayout · error · IllegalStateException

TabEntitys can not be NULL or EMPTY !

Error message

TabEntitys can not be NULL or EMPTY !

What it means

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.

Solutions

  1. Pass a non-empty ArrayList<CustomTabEntity> with one entry per tab.
  2. Guard the call site: only invoke setTabData after confirming list != null && !list.isEmpty().
  3. If data loads asynchronously, call setTabData inside the load callback once items are available.
  4. Wrap the call in try-catch for IllegalStateException if empty data is an expected, recoverable condition.

Example fix

// before
layout.setTabData(mTabEntitys);
// after
if (mTabEntitys != null && !mTabEntitys.isEmpty()) {
    layout.setTabData(mTabEntitys);
}
Defensive patterns

Strategy: validation

Validate before calling

if (tabEntitys != null && !tabEntitys.isEmpty()) {
    commonTabLayout.setTabData(tabEntitys);
}

Type guard

boolean isValidTabData(ArrayList<CustomTabEntity> list) {
    return list != null && !list.isEmpty();
}

Try / catch

try {
    commonTabLayout.setTabData(tabEntitys);
} catch (IllegalStateException e) {
    Log.e("TabLayout", "No tab entities provided", e);
}

Prevention

When it happens

Trigger: Calling setTabData(null), calling setTabData(new ArrayList<>()), or passing a list that was filtered/populated asynchronously and ended up empty before the call.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of H07000223/FlycoTabLayout@528fcffe88 (2026-09-08). Data as JSON: /api/errors/dfb1e00bd4a1bffd. Report an issue: GitHub.

Appendix: source

Thrown at FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/CommonTabLayout.java:196

        mTextBold = ta.getInt(R.styleable.CommonTabLayout_tl_textBold, TEXT_BOLD_NONE);
        mTextAllCaps = ta.getBoolean(R.styleable.CommonTabLayout_tl_textAllCaps, false);

        mIconVisible = ta.getBoolean(R.styleable.CommonTabLayout_tl_iconVisible, true);
        mIconGravity = ta.getInt(R.styleable.CommonTabLayout_tl_iconGravity, Gravity.TOP);
        mIconWidth = ta.getDimension(R.styleable.CommonTabLayout_tl_iconWidth, dp2px(0));
        mIconHeight = ta.getDimension(R.styleable.CommonTabLayout_tl_iconHeight, dp2px(0));
        mIconMargin = ta.getDimension(R.styleable.CommonTabLayout_tl_iconMargin, dp2px(2.5f));

        mTabSpaceEqual = ta.getBoolean(R.styleable.CommonTabLayout_tl_tab_space_equal, true);
        mTabWidth = ta.getDimension(R.styleable.CommonTabLayout_tl_tab_width, dp2px(-1));
        mTabPadding = ta.getDimension(R.styleable.CommonTabLayout_tl_tab_padding, mTabSpaceEqual || mTabWidth > 0 ? dp2px(0) : dp2px(10));

        ta.recycle();
    }

    public void setTabData(ArrayList<CustomTabEntity> tabEntitys) {
        if (tabEntitys == null || tabEntitys.size() == 0) {
            throw new IllegalStateException("TabEntitys can not be NULL or EMPTY !");
        }

        this.mTabEntitys.clear();
        this.mTabEntitys.addAll(tabEntitys);

        notifyDataSetChanged();
    }

    /** 关联数据支持同时切换fragments */
    public void setTabData(ArrayList<CustomTabEntity> tabEntitys, FragmentActivity fa, int containerViewId, ArrayList<Fragment> fragments) {
        mFragmentChangeManager = new FragmentChangeManager(fa.getSupportFragmentManager(), containerViewId, fragments);
        setTabData(tabEntitys);
    }

    /** 更新数据 */
    public void notifyDataSetChanged() {
        mTabsContainer.removeAllViews();
        this.mTabCount = mTabEntitys.size();

View on GitHub (pinned to 528fcffe88)