-2

I'd like to search using invoice number but it's give an error in Invoice no how to solve it. here is my filter method & error is:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase(java.util.Locale)' on a null object reference

public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
billmod.clear();
if (charText.length() == 0) {
    billmod.addAll(arraylist);

} else {
    for (BillModel st : arraylist) {
        if (st.getBill_tableno().toLowerCase(Locale.getDefault()).contains(charText)) {
            billmod.add(st);

        }
        else if(st.getBill_date().toLowerCase(Locale.getDefault()).contains(charText)) {
            billmod.add(st);

        } else if(st.getBill_amount().toLowerCase(Locale.getDefault()).contains(charText)) {
            billmod.add(st);
        }
        else if(st.getIncvoice_no().toLowerCase(Locale.getDefault()).contains(charText)) {
            billmod.add(st);
        }

    }
}
notifyDataSetChanged();
}
MWiesner
  • 8,868
  • 11
  • 36
  • 70
np5293
  • 7
  • 2
  • How are you setting the value or arraylist? (st.getBill_tableno() is returning null. Please check if values are being saved to arraylist properly or not – Sonam Jun 08 '17 at 11:10

1 Answers1

0

It seems some Strings are null, probably in your locale reference to BillModel in the for loop.

Make sure the data inside this variable is not null before doing any operations on it.

Webster
  • 164
  • 3