OutOfBoundException in searchview Android while searching with invoice Id-ThrowExceptions

Exception or error:

I am implementing a layout in which a list of bills is coming from API, Now I give a search view widget and I am trying to search bills with invoice Id. Now problem is that invoice id is type of long, now when I type 15 or 16 digits number in SearchView the app is crashing. I am storing my invoiceId in a long data type, and I am searching a number which is out of long. so I want to restrict the digits in SearchView android studio. I search a lot but didn’t get any answer.

 public Filter getFilter() {
        return new Filter() {
            @Override
            protected FilterResults performFiltering(CharSequence constraint) {

                String charString = constraint.toString();

                if (charString.isEmpty()) {
                    bill_lists = filterSearch;
                } else {

                    List<Manager_Bill_Model> filterList = new ArrayList<>();

                    for (Manager_Bill_Model item : filterSearch) {

                        long id = item.getInvoiceID();
                        if (id == Long.parseLong(charString)) {

                            filterList.add(item);
                        }
                    }

                    bill_lists = filterList;

                }

                FilterResults filterResults = new FilterResults();
                filterResults.values = bill_lists;

                return filterResults;
            }

            @Override
            protected void publishResults(CharSequence constraint, FilterResults results) {

                bill_lists = (List<Manager_Bill_Model>) results.values;
                notifyDataSetChanged();
            }
        };
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *