public Order gimmeThePendingOrderToDeliver(String _id, String my_phone) {
for (int i = 0; i < orderSortedList.size(); i++) {
Order o = orderSortedList.get(i);
boolean a = o.isCanceled_by_user(), b = o.isCanceled_by_owner(), c = o.isDelivered();
String d = o.getDelivery_guy();
if (_id.equals(o.get_id()) && !a && !b && !c && d.equals(my_phone)) {
Toast.makeText(context, "IM HERE", Toast.LENGTH_SHORT).show();
return o;
}
}
Toast.makeText(context, orderSortedList.get(0).get_id(), Toast.LENGTH_SHORT).show();
return null;
}
cant iterate Android SortedList returns error as descriped in the title ,, any help will be appreciated . THANKS in advance.
When
orderSortedListis empty, it doesn't enter theforloop, and thus, it immediately reaches the bottommostToaststatement whereorderSortedList.get(0)produces anIndexOutOfBoundsExceptionsince the list is empty.