title: custom listview with filter search edittext
body: <p>Set myself the challenge of creating a custom listview and being able to filter that listview using an editbox filter. All of the layout appears fine but when I type into the query box I get "virtual method on a null object reference.</p>
  
  <p>Here's my code below, what am I doing wrong. I want the listview to change dynamically based on text in the box.</p>
  
  <p>LogCat</p>
  
  <pre><code>05-27 01:20:16.738  10798-10798/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
  Process: com.ak273.chefs, PID: 10798
  java.lang.NullPointerException: Attempt to invoke virtual method 'int com.ak273.chefs.listBuilder.getCount()' on a null object reference
          at com.ak273.chefs.searchList.getCount(searchList.java:35)
          at android.widget.AdapterView$AdapterDataSetObserver.onChanged(AdapterView.java:806)
          at android.widget.AbsListView$AdapterDataSetObserver.onChanged(AbsListView.java:6117)
          at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
          at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
          at com.ak273.chefs.searchList$ItemFilter.publishResults(searchList.java:125)
          at android.widget.Filter$ResultsHandler.handleMessage(Filter.java:282)
          at android.os.Handler.dispatchMessage(Handler.java:102)
          at android.os.Looper.loop(Looper.java:135)
          at android.app.ActivityThread.main(ActivityThread.java:5221)
          at java.lang.reflect.Method.invoke(Native Method)
          at java.lang.reflect.Method.invoke(Method.java:372)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  </code></pre>
  
  <p>mainActivity.java</p>
  
  <pre><code>            final ArrayList&lt;Integer&gt; recipeIDS = recipeID;
  
              final listBuilder adapterSearch = new listBuilder(getActivity(), recipeImgs, recipeNames, recipeDesc);
  
              final searchList search = new searchList(getActivity(),adapterSearch);
  
              listView = (ListView)rootView.findViewById(R.id.list_search);
  
              listView.setAdapter(search);
  
              listView.setClickable(true);
              listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
                  @Override
                  public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
                      int addRecipeID = recipeIDS.get(position);
  
                      Log.d(YOUR_SEARCH, "CLICKED ON RECIPE: " + addRecipeID);
  
                      Intent intent = new Intent(parent.getContext(), individual_recipe.class);
  
                      Bundle bundle = dbHelper.getFullRecipe(addRecipeID);
                      bundle.putInt("recipeID", addRecipeID);
                      intent.putExtras(bundle);
  
                      startActivity(intent);
  
                  }
  
              });
  
              EditText recipeSearch = (EditText)rootView.findViewById(R.id.edit_search);
              recipeSearch.addTextChangedListener(new TextWatcher() {
                  @Override
                  public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  
                  }
  
                  @Override
                  public void onTextChanged(CharSequence s, int start, int before, int count) {
  
                      final String ON_TEXT_CHANGED = "ON TEXT CHANGED";
  
                      Log.d(ON_TEXT_CHANGED, "[ " + s + " ]");
  
                      search.getFilter().filter(s.toString());
  
                  }
  
                  @Override
                  public void afterTextChanged(Editable s) {
  
                  }
              });
  </code></pre>
  
  <p>listBuilder.java</p>
  
  <pre><code>public class listBuilder extends ArrayAdapter&lt;String&gt; implements Filterable {
  
  String[] recipeNames;
  String[] recipeDesc;
  ArrayList&lt;Uri&gt; recipeImgs;
  Context context;
  
  public listBuilder(Activity context, ArrayList&lt;Uri&gt; recipeImgs, String[] text, String[] recipeDesc){
      super(context, R.layout.list_recipe, text);
  
      this.recipeNames = text;
      this.recipeDesc = recipeDesc;
      this.recipeImgs = recipeImgs;
      this.context = context;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
  
      LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
      View single_row = inflater.inflate(R.layout.list_recipe, null, true);
  
      ImageView imageView = (ImageView)single_row.findViewById(R.id.list_recipePic);
  
      TextView textView = (TextView)single_row.findViewById(R.id.list_recipeName);
      textView.setText(recipeNames[position]);
  
      textView = (TextView)single_row.findViewById(R.id.list_recipeDesc);
      textView.setText(recipeDesc[position]);
  
      imageView.setImageURI(recipeImgs.get(position));
  
      return single_row;
  
  }
  
  }
  </code></pre>
  
  <p>searchList.java Code:</p>
  
  <pre><code>searchList.java
  
  public class searchList extends BaseAdapter implements Filterable {
  
  private listBuilder originalList = null;
  private listBuilder filteredList = null;
  private LayoutInflater layoutInflater;
  private int cnt;
  private ItemFilter itemFilter = new ItemFilter();
  
  public searchList(Context context, listBuilder data) {
      this.originalList = data;
      this.filteredList = data;
      layoutInflater = LayoutInflater.from(context);
  }
  
  @Override
  public int getCount() {
      return filteredList.getCount();
  }
  
  @Override
  public Object getItem(int position) {
      return filteredList.getItem(position);
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
  
      ViewHolder holder;
  
      if (convertView == null) {
  
          convertView = layoutInflater.inflate(R.layout.list_recipe,null);
  
          holder = new ViewHolder();
          holder.image = (ImageView)convertView.findViewById(R.id.list_recipePic);
          holder.title = (TextView)convertView.findViewById(R.id.list_recipeName);
          holder.desc = (TextView)convertView.findViewById(R.id.list_recipeDesc);
  
          convertView.setTag(holder);
  
      } else {
  
          holder = (ViewHolder)convertView.getTag();
  
      }
  
      holder.image.setImageURI(filteredList.recipeImgs.get(position));
      holder.title.setText(filteredList.recipeNames[position]);
      holder.desc.setText(filteredList.recipeDesc[position]);
  
      return convertView;
  }
  
  static class ViewHolder {
      ImageView image;
      TextView title;
      TextView desc;
  }
  
  public Filter getFilter() {
      return itemFilter;
  }
  
  private class ItemFilter extends Filter {
  
      @Override
      protected FilterResults performFiltering(CharSequence constraint) {
  
          String filterString = constraint.toString().toLowerCase();
  
          FilterResults results = new FilterResults();
  
          final String[] list = originalList.recipeNames;
  
          int count = list.length;
  
          final ArrayList&lt;String&gt; newList = new ArrayList&lt;String&gt;(count);
  
          String filterableString;
  
          for (int i = 0; i &lt; count; i++) {
  
              filterableString = newList.get(i);
  
              if (filterableString.toLowerCase().contains(filterString)) {
                  newList.add(filterableString);
              }
  
          }
  
          results.values = newList;
          results.count = newList.size();
  
          return results;
      }
  
      @Override
      protected void publishResults(CharSequence constraint, FilterResults results) {
          filteredList = (listBuilder)results.values;
          //cnt = results.count;
  
          notifyDataSetChanged();
      }
  
  }
  }
  </code></pre>