shehuan / GroupIndexLib

ItemDecoration实现的仿通信录分组索引效果,同时提供SideBar
Apache License 2.0
30 stars 9 forks source link

数据为空时 数组越界崩溃 #2

Closed Likeyong closed 6 years ago

Likeyong commented 6 years ago

E/AndroidRuntime: FATAL EXCEPTION: main Process: com.nj.wellsign, PID: 1611 java.lang.ArrayIndexOutOfBoundsException: length=73; index=-1 at java.util.ArrayList.get(ArrayList.java:413) at com.othershe.groupindexlib.decoration.GroupHeaderItemDecoration.onDrawOver(GroupHeaderItemDecoration.java:100) at android.support.v7.widget.RecyclerView.draw(RecyclerView.java:3991) at android.view.View.updateDisplayListIfDirty(View.java:16081) at android.view.View.draw(View.java:16865)

好像是在这里没有对 position 为-1 时候进行判断,因为 int position = ((LinearLayoutManager)((LinearLayoutManager)parent.getLayoutManager())).findFirstVisibleItemPosition(); 这里如果没有可见的item的话 会返回-1 , String tag = (String)this.tags.get(position);这里对-1取值,所以出了问题。

在GroupHeaderItemDecoration 这个类的 84 和85 行,希望大神能看一下。谢谢了

Likeyong commented 6 years ago

build.gradle 已经引用了1.0.1版本,报错是在 100 行 , 但是打开源码显示问题定位在84行。但是应该是这里String tag = (String)this.tags.get(position);出了问题