@@ -76,7 +76,7 @@ public IndicatorView(Context context, AttributeSet attrs, int defStyleAttr) {
7676
7777 @ Override
7878 protected void onDraw (Canvas canvas ) {
79- if (indicators == null ) return ;
79+ if (indicators == null || indicators . length == 0 ) return ;
8080 for (int i =0 ; i <indicators .length ; i ++){
8181 indicators [i ].draw (canvas );
8282 }
@@ -95,6 +95,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
9595 @ Override
9696 protected void onLayout (boolean changed , int left , int top , int right , int bottom ) {
9797 if (viewPager == null ) return ;
98+ if (indicators == null || indicators .length == 0 ) return ;
9899 int haftWidth = getWidth () / 2 ;
99100 int count = viewPager .getAdapter ().getCount ();
100101 int y = getHeight ()/2 ;
@@ -130,6 +131,7 @@ public void onPageScrolled(int position, float positionOffset, int positionOffse
130131
131132 @ Override
132133 public void onPageSelected (int position ) {
134+ if (indicators == null || indicators .length == 0 ) return ;
133135 beforePosition = currentPosition ;
134136 currentPosition = position ;
135137 if (beforePosition == currentPosition ) return ;
@@ -156,6 +158,7 @@ public void setViewPager(ViewPager viewPager) {
156158 this .viewPager = viewPager ;
157159 viewPager .addOnPageChangeListener (this );
158160 int count = viewPager .getAdapter ().getCount ();
161+ if (count == 0 ) return ;
159162 indicators = new Indicator [viewPager .getAdapter ().getCount ()];
160163 for (int i = 0 ; i < count ; i ++){
161164 indicators [i ] = indicatorFactory .getIndicatorBasic (type , radius , i == 0 );
0 commit comments