H07000223/FlycoTabLayout · error · IllegalStateException
Titles can not be EMPTY !
Error message
Titles can not be EMPTY !
What it means
In SlidingTabLayout.setViewPager(ViewPager, String[]), a null or zero-length titles array throws IllegalStateException "Titles can not be EMPTY !". Each tab needs a title string; an empty array would leave the tab strip blank and desynchronized from the adapter.
Solutions
- Pass a titles array with exactly one non-null entry per page.
- Validate titles != null && titles.length > 0 before the call, and also match vp.getAdapter().getCount() (a later check throws otherwise).
- Defer setViewPager until titles are loaded, or use the 1-arg setViewPager with an adapter that supplies titles via getPageTitle().
- Catch IllegalStateException when empty titles can legitimately occur at startup.
Example fix
// before
slidingTabLayout.setViewPager(viewPager, new String[0]);
// after
String[] titles = {"Tab 1", "Tab 2"};
slidingTabLayout.setViewPager(viewPager, titles); Defensive patterns
Strategy: validation
Validate before calling
if (titles != null && titles.length > 0 && titles.length == vp.getAdapter().getCount()) {
slidingTabLayout.setViewPager(vp, titles);
} Type guard
boolean isValidTitleSet(ViewPager vp, String[] titles) {
return titles != null && titles.length > 0
&& vp != null && vp.getAdapter() != null
&& titles.length == vp.getAdapter().getCount();
} Try / catch
try {
slidingTabLayout.setViewPager(vp, titles);
} catch (IllegalStateException e) {
Log.e("SlidingTabLayout", "titles null/empty", e);
} Prevention
- Derive titles from the same collection that feeds the adapter.
- Defer binding until both pages and titles are ready.
- Never pass new String[0] placeholders to production code paths.
- Write a test asserting titles.length == adapter.getCount().
When it happens
Trigger: Passing titles == null or titles.length == 0 to the two-argument setViewPager; passing an array built from an empty list or missing string resources.
Common situations: Titles loaded asynchronously and not yet populated when setViewPager runs; localized string arrays resolving to nothing; copy-paste of the 1-arg setViewPager call without adding titles.
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
- TabEntitys can not be NULL or EMPTY !
- Titles can not be NULL or EMPTY !
- Titles length must be the same as the page count !
- ViewPager or ViewPager adapter can not be NULL !
- ViewPager can not be NULL !
AI-assisted analysis of H07000223/FlycoTabLayout@528fcffe88 (2026-09-08).
Data as JSON: /api/errors/7ad42adb028e1489.
Report an issue: GitHub.
Appendix: source
Thrown at FlycoTabLayout_Lib/src/main/java/com/flyco/tablayout/SlidingTabLayout.java:192
if (vp == null || vp.getAdapter() == null) {
throw new IllegalStateException("ViewPager or ViewPager adapter can not be NULL !");
}
this.mViewPager = vp;
this.mViewPager.removeOnPageChangeListener(this);
this.mViewPager.addOnPageChangeListener(this);
notifyDataSetChanged();
}
/** 关联ViewPager,用于不想在ViewPager适配器中设置titles数据的情况 */
public void setViewPager(ViewPager vp, String[] titles) {
if (vp == null || vp.getAdapter() == null) {
throw new IllegalStateException("ViewPager or ViewPager adapter can not be NULL !");
}
if (titles == null || titles.length == 0) {
throw new IllegalStateException("Titles can not be EMPTY !");
}
if (titles.length != vp.getAdapter().getCount()) {
throw new IllegalStateException("Titles length must be the same as the page count !");
}
this.mViewPager = vp;
mTitles = new ArrayList<>();
Collections.addAll(mTitles, titles);
this.mViewPager.removeOnPageChangeListener(this);
this.mViewPager.addOnPageChangeListener(this);
notifyDataSetChanged();
}
/** 关联ViewPager,用于连适配器都不想自己实例化的情况 */
public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, ArrayList<Fragment> fragments) {
if (vp == null) {View on GitHub (pinned to 528fcffe88)