0

I am trying to add search functionality to a custom adapter that calls a list from a web service. However when I try and enter anything into the search text field the app crashes. I am getting a

"java.lang.NullPointerException: Attempt to invoke virtual method 'android.widget.Filter android.widget.ArrayAdapter.getFilter()' on a null object reference" error.

I understand what this means but I am not sure what to replace the code with.

Thanks

public class CallSoapGetTicketHoldersForEvent extends AsyncTask<GetTicketHolderForEventParams, Void, String> {

    private Exception exception;

    @Override
    protected String doInBackground(GetTicketHolderForEventParams... params) {
        return params[0].foo.GetTicketHoldersForEvent(params[0].eventname,params[0].username,params[0].password);
    }

    protected void onPostExecute(String result) {

        // Calling Application class (see application tag in AndroidManifest.xml)
        Local.Set(getApplicationContext(), "TicketHolders", result);

         //sets list view for ticket holder information
        String[] RowData = result.toString().split(";");
        List<String> TicketholdersArray = new ArrayList<>();
        for(int x=0;x<RowData.length;x++)
        {
            TicketholdersArray.add(RowData[x].toString());
        }

        ListView listView1 = (ListView) findViewById(R.id.your_list_view_id);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(GuestlistActivity.this,R.layout.liststyle, TicketholdersArray);
        adapter.setDropDownViewResource(R.layout.spinnerstyledrop);
        listView1.setAdapter(adapter);

        edtSearch = (EditText) findViewById(R.id.edtsearch);

        lstSearch = (ListView)findViewById(R.id.LstSearch);

        lstSearch.setAdapter(adapter);

        edtSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {}

            @Override
            public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
                GuestlistActivity.this.adapter.getFilter().filter(charSequence);
            }

            @Override
            public void afterTextChanged(Editable s) {}
        });
    }
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

Seems your filter set is null. Make sure your not passing null values in your ArrayAdapter.

albeee
  • 1,452
  • 1
  • 12
  • 20