H07000223/FlycoTabLayout · error · IllegalStateException

Titles can not be NULL or EMPTY !

Error message

Titles can not be NULL or EMPTY !

What it means

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.

Solutions

  1. Pass a String[] with at least one title, one per segment.
  2. Validate before calling: if (titles != null && titles.length > 0) before setTabData.
  3. If titles come from remote/config, supply defaults or skip rendering the layout until data arrives.
  4. Catch IllegalStateException around the call when emptiness is an expected runtime condition.

Example fix

// before
segmentTabLayout.setTabData(titles);
// after
if (titles != null && titles.length > 0) {
    segmentTabLayout.setTabData(titles);
}
Defensive patterns

Strategy: validation

Validate before calling

if (titles != null && titles.length > 0) {
    segmentTabLayout.setTabData(titles);
}

Type guard

boolean isValidTitles(String[] titles) {
    return titles != null && titles.length > 0;
}

Try / catch

try {
    segmentTabLayout.setTabData(titles);
} catch (IllegalStateException e) {
    Log.e("SegmentTabLayout", "titles null/empty", e);
}

Prevention

When it happens

Trigger: Passing a null String[] to setTabData, or passing titles = new String[0]; also passing an array built from an empty resource/collection.

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

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/ebfadd2b7f5362d9. Report an issue: GitHub.

Appendix: source

Thrown at FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SegmentTabLayout.java:166

        mTextSelectColor = ta.getColor(R.styleable.SegmentTabLayout_tl_textSelectColor, Color.parseColor("#ffffff"));
        mTextUnselectColor = ta.getColor(R.styleable.SegmentTabLayout_tl_textUnselectColor, mIndicatorColor);
        mTextBold = ta.getInt(R.styleable.SegmentTabLayout_tl_textBold, TEXT_BOLD_NONE);
        mTextAllCaps = ta.getBoolean(R.styleable.SegmentTabLayout_tl_textAllCaps, false);

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

        mBarColor = ta.getColor(R.styleable.SegmentTabLayout_tl_bar_color, Color.TRANSPARENT);
        mBarStrokeColor = ta.getColor(R.styleable.SegmentTabLayout_tl_bar_stroke_color, mIndicatorColor);
        mBarStrokeWidth = ta.getDimension(R.styleable.SegmentTabLayout_tl_bar_stroke_width, dp2px(1));

        ta.recycle();
    }

    public void setTabData(String[] titles) {
        if (titles == null || titles.length == 0) {
            throw new IllegalStateException("Titles can not be NULL or EMPTY !");
        }

        this.mTitles = titles;

        notifyDataSetChanged();
    }

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

    /** 更新数据 */
    public void notifyDataSetChanged() {
        mTabsContainer.removeAllViews();
        this.mTabCount = mTitles.length;
        View tabView;

View on GitHub (pinned to 528fcffe88)