title: Recycler view Array index outof bound Incossitency Error while SwipetoRefresh and recycler scrolling same time
body: <p>i am using 23.1.1 RecyclerView, when swipe to refresh is started and in that case when i am scrolling my RecyclerView it will crash and gives me Error  </p>
  
  <p>Here is my ErrorLog,</p>
  
  <pre><code>    java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{39e0644b position=6 id=-1, oldPos=-1, pLpos:-1 no parent}
  at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4251)
  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4382)
  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
  at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
  at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
  at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
  at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1161)
  at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:1018)
  at android.support.v7.widget.RecyclerView.scrollByInternal(RecyclerView.java:1492)
  at android.support.v7.widget.RecyclerView.onTouchEvent(RecyclerView.java:2416)
  at android.view.View.dispatchTouchEvent(View.java:8476)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2401)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2092)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2407)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2106)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2369)
  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1719)
  at android.app.Activity.dispatchTouchEvent(Activity.java:2752)
  at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
  at android.support.v7.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2330)
  at android.view.View.dispatchPointerEvent(View.java:8671)
  at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4193)
  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4059)
  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3604)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:36
  </code></pre>
  
  <p>These error only happens when i am using swipe to refresh layout.</p>
  
  <p>In  onBindViewHolder method in adapter i am calling an event for loadmore data when last item visible</p>
  
  <pre><code>@Override
      public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
  
  
          if(position == data.size() -1 &amp;&amp; data.size() &gt;= AppConstants.LIST_PAGE_SIZE){
  
              EventBus.getDefault().postSticky(new LoadMoreDataEvent(getPageIndex()));
          }
  }
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>after clear list and when i am trying to notify adapter i getting this error , These is a bug in recycler view .  i just clear list and set adapter null and its working.</p>
  
  <pre><code>list.clear();
  mAdapter.notifyDataSetChanged();
  </code></pre>