title: Implementing search bar and getting 'java.lang.Object[] java.util.Collection.toArray()' on a null object reference error
body: <p>I am new to android studio and I have been trying to implement a search bar onto my app and I've come across a building error. It install's fine but when I try to open the app on my phone shows "application has stopped". </p>
  
  <p><strong>Logcat (Errors):</strong></p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.sliteproj, PID: 1445
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sliteproj/com.example.sliteproj.MainActivity}: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object[] java.util.Collection.toArray()' on a null object reference
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
      at android.app.ActivityThread.-wrap11(Unknown Source:0)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
      at android.os.Handler.dispatchMessage(Handler.java:105)
      at android.os.Looper.loop(Looper.java:164)
      at android.app.ActivityThread.main(ActivityThread.java:6944)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
   Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object[] java.util.Collection.toArray()' on a null object reference
      at java.util.ArrayList.&lt;init&gt;(ArrayList.java:191)
      at com.example.sliteproj.Adapter.&lt;init&gt;(Adapter.java:34)
      at com.example.sliteproj.MainActivity.showRecord(MainActivity.java:57)
      at com.example.sliteproj.MainActivity.onCreate(MainActivity.java:41)
      at android.app.Activity.performCreate(Activity.java:7183)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) 
      at android.app.ActivityThread.-wrap11(Unknown Source:0) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
      at android.os.Handler.dispatchMessage(Handler.java:105) 
      at android.os.Looper.loop(Looper.java:164) 
      at android.app.ActivityThread.main(ActivityThread.java:6944) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 
  </code></pre>
  
  <p>I understand that this is a frequently asked question, and have looked through the other answers and solutions. I have tried initializing the List but still, am unable to fix the error.I think I am having trouble understanding where the initialization is exactly needed.</p>
  
  <p><strong>My code (Adapter.java):</strong></p>
  
  <pre><code>public class Adapter extends RecyclerView.Adapter&lt;Adapter.Holder&gt; implements 
  Filterable {
  private Context context;
  private ArrayList&lt;Model&gt; arrayList;
  private ArrayList&lt;Model&gt; exampleArrayList;
  
  DatabaseHelper databaseHelper;
  
  public Adapter(Context context, ArrayList&lt;Model&gt; arrayList) {
      this.context = context;
      this.arrayList = arrayList;
      exampleArrayList = new ArrayList&lt;&gt;(exampleArrayList);
  
      databaseHelper = new DatabaseHelper(context);
  }
  
  @Override
  public Filter getFilter() {
      return exampleFilter;
  }
  
  private Filter exampleFilter = new Filter() {
      @Override
      protected FilterResults performFiltering(CharSequence constraint) {
          List&lt;Model&gt; filteredList = new ArrayList&lt;&gt;();
  
          if (constraint == null || constraint.length() == 0) {
              filteredList.addAll(exampleArrayList);
          } else {
              String filterPattern = constraint.toString().toLowerCase().trim();
  
              for (Model item: exampleArrayList) {
                  if (item.getName().toLowerCase().contains(filterPattern)) {
                      filteredList.add(item);
                  }
              }
          }
  
          FilterResults results = new FilterResults();
          results.values = filteredList;
  
          return results;
      }
  
      @Override
      protected void publishResults(CharSequence constraint, FilterResults results) {
          arrayList.clear();
          arrayList.addAll((List) results.values);
          notifyDataSetChanged();
      }
  };
  }
  </code></pre>