Try to fix ArrayIndexOutOfBoundsException

We sometimes get an ArrayIndexOutOfBoundsException when trying to create the ItemPagerFragment.
After trying quite a few things already, Google Play still reports the crash.
Previous experiments showed that the index is not larger than the array length. Because it is
an AIOOB Exception and not a NPE, the array must be created correctly. Maybe it is a negative index.
Might be caused by getAdapterPosition() returning NO_POSITION (-1).
This commit is contained in:
ByteHamster 2020-01-04 23:57:48 +01:00
parent 98d9c4cceb
commit 38e2abd2fe
1 changed files with 3 additions and 2 deletions

View File

@ -245,8 +245,9 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR
public void onClick(View v) {
MainActivity mainActivity = mainActivityRef.get();
if (mainActivity != null) {
long[] ids = itemAccess.getItemsIds().toArray();
mainActivity.loadChildFragment(ItemPagerFragment.newInstance(ids, getAdapterPosition()));
LongList itemIds = itemAccess.getItemsIds();
long[] ids = itemIds.toArray();
mainActivity.loadChildFragment(ItemPagerFragment.newInstance(ids, itemIds.indexOf(item.getId())));
}
}