본문 바로가기

🐛 버그

[Bug / RecyclerView] java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionNotificationHolder

🐛 SwipeRefreshLayout에서 refresh시 발생 

주 원인  : 데이터 변경 시 리사이클러뷰의 뷰 홀더와 실 데이터가 불일치 

SwipeRefreshLayout에서 refresh 발생 시 Adapter의 아이템을 clear 하고 새로 그렸는데, 이 과정에서 문제가 발생한 거 같다

 


 

시도한 방법 

1. bindViewHolder할 때 holder.bind(아이템목록[position])을 

holder.bind(아이템목록[absoluteAdapterPosition])으로 변경  -> 똑같이 에러 발생

 

2. refresh후 데이터 가져올 때 

clear()를 시키지 않고, 데이터를 가져온 후 기존의 데이터와 바꿈!  -> 성공

 

🔑 recyclerView는 기존의 뷰 홀더를 재사용하려고 하지만, clear시키면 기존에 데이터와 맞지 않기때문에 에러 발생