If I try to hide a row with evrencoskun's TableView
, but have not called setRowHeadItems
(because my table doesn't have row labels) then my app crashes:
FATAL EXCEPTION: main
Process: com.example.app, PID: 20150
java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
at java.util.Objects.checkIndex(Objects.java:359)
at java.util.ArrayList.remove(ArrayList.java:511)
at com.evrencoskun.tableview.adapter.recyclerview.AbstractRecyclerViewAdapter.deleteItem(AbstractRecyclerViewAdapter.java:99)
at com.evrencoskun.tableview.adapter.AbstractTableAdapter.removeRow(AbstractTableAdapter.java:244)
at com.evrencoskun.tableview.handler.VisibilityHandler.hideRow(VisibilityHandler.java:63)
at com.evrencoskun.tableview.TableView.hideRow(TableView.java:618)
...
I have checked that the table has been given data (including the row I am trying to hide) before the crash.
When the row is removed, we eventually get to a the removeRow
function in AbstractTableAdapter
:
public void removeRow(int rowPosition) {
this.mCellRecyclerViewAdapter.deleteItem(rowPosition);
this.mRowHeaderRecyclerViewAdapter.deleteItem(rowPosition);
}
The error happens on the second line, because the dataset that backs up the mRowHeaderRecyclerViewAdapter
is empty.
To fix this, you could change the library to do a check if there are row headers before it deletes the corresponding one, or simply create arbitrary row headers and then set their width to 0 in the XML:
app:row_header_width="0dp"