title: java.lang.IllegalArgumentException is occuring
body: <p>I coded one handler to maintain the auto-scroll of a recyclerview. it's working fine. but the issue I am faced when there is only one item in the recyclerview. my app got crashed and when I checked logcat I am getting an error like java.lang.IllegalArgumentException: Invalid target position.</p>
  
  <p>Here is my Custom LinearLayoutManager Class</p>
  
  <pre><code>public class CustomLinearLayoutManager extends LinearLayoutManager {
  
      public CustomLinearLayoutManager (Context context) {
          super(context);
      }
  
      public CustomLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
          super(context, orientation, reverseLayout);
      }
  
      public CustomLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
          super(context, attrs, defStyleAttr, defStyleRes);
      }
  
      @Override
      public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
          final LinearSmoothScroller linearSmoothScroller =
                  new LinearSmoothScroller(recyclerView.getContext()) {
                      private static final float MILLISECONDS_PER_INCH = 100f;
  
                      @Override
                      public PointF computeScrollVectorForPosition(int targetPosition) {
                          return CustomLinearLayoutManager.this
                                  .computeScrollVectorForPosition(targetPosition);
                      }
  
                      @Override
                      protected float calculateSpeedPerPixel
                              (DisplayMetrics displayMetrics) {
                          return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
                      }
                  };
          linearSmoothScroller.setTargetPosition(position);
          startSmoothScroll(linearSmoothScroller);
      }
  }
  </code></pre>
  
  <p>Here is a getting error on this line:</p>
  
  <pre><code>startSmoothScroll(linearSmoothScroller);
  </code></pre>
  
  <p>Error is - CustomLinearLayoutManager.smoothScrollToPosition
  java.lang.IllegalArgumentException: Invalid target position</p>
  
  <p>Here is the code for the home fragment</p>
  
  <pre><code> recyclerViewHeaderSlider.setLayoutManager(new CustomLinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
          headerSliderAdapter.setOnClick(this);
          recyclerViewHeaderSlider.setAdapter(headerSliderAdapter);
          final int speedScroll = 6000;
          final Handler handler = new Handler();
          final Runnable runnable = new Runnable() {
              int count = 0;
              boolean flag = true;
  
              @Override
              public void run() {
                  if (count &lt; headerSliderAdapter.getItemCount()) {
                      if (count == headerSliderAdapter.getItemCount() - 1) {
                          flag = false;
                      } else if (count == 0) {
                          flag = true;
                      }
                      if (flag) count++;
                      else count--;
  
                      recyclerViewHeaderSlider.smoothScrollToPosition(count);
                      handler.postDelayed(this, speedScroll);
                  }
              }
          };
  
          handler.postDelayed(runnable, speedScroll);
  </code></pre>
  
  <p>Here is a getting error on this line:</p>
  
  <pre><code>recyclerViewHeaderSlider.smoothScrollToPosition(count);
  </code></pre>
  
  <p>Error is - java.lang.IllegalArgumentException: Invalid target position</p>