For loop 为什么我会有IndexOutOfBoundsException?
这是我的for循环,我的for循环错了吗?我已经很长时间没有做循环了,所以我还是一个初学者,如果有人能看看我的问题,我会非常感激For loop 为什么我会有IndexOutOfBoundsException?,for-loop,indexoutofboundsexception,For Loop,Indexoutofboundsexception,这是我的for循环,我的for循环错了吗?我已经很长时间没有做循环了,所以我还是一个初学者,如果有人能看看我的问题,我会非常感激 for (int i = 0; i < tabLayout.getTabCount(); i++) { TabLayout.Tab tab = tabLayout.getTabAt(i); if (tab != null) { tab.setCustomView(mSectionsPagerAdapter.getTabView(i
for (int i = 0; i < tabLayout.getTabCount(); i++) {
TabLayout.Tab tab = tabLayout.getTabAt(i);
if (tab != null) {
tab.setCustomView(mSectionsPagerAdapter.getTabView(i));
}else{
System.out.println("ERROR---TAB IS NULL---ERROR");
}
}
这是什么编程语言?您是否记录了
tabLayout.getTabCount()
以检查选项卡的数量?为什么要返回3页中的4页。Java有一个0索引?在计算机科学中有两件困难的事情:缓存失效、命名和关闭一个错误。这发生在哪一行?当你出错时,你要做的两件事是:1。弄清楚它在哪条线上;2.在线查找错误
@Override
public int getCount() {
// Show 3 total pages.
return 4;
}
@Override
public CharSequence getPageTitle(int position) {
// Generate title based on item position
// return tabTitles[position];
// getDrawable(int i) is deprecated, use getDrawable(int i, Theme theme) for min SDK >=21
// or ContextCompat.getDrawable(Context context, int id) if you want support for older versions.
// Drawable image = context.getResources().getDrawable(iconIds[position], context.getTheme());
// Drawable image = context.getResources().getDrawable(imageResId[position]);
Drawable image = ContextCompat.getDrawable(MainActivity.this, imageResId[position]);
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
SpannableString sb = new SpannableString(" ");
ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM);
sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return sb;
}