title: Attempt to invoke virtual method '(java.lang.String)' on a null object reference
body: <p>New to Java and Android Studio here.</p>
  <p>Working on this image application, and I am trying to format a query from a search bar that replaces any white space into underscores and returns a string with the formatted string.</p>
  <p>Been having a hard time trying to analyze this code, it seems that it's returning a null value.</p>
  <p><strong>Error</strong></p>
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.image_chan/com.example.image_chan.Main}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.image_chan.core.SearchFormatter.FormatToTagsStr(java.lang.String)' on a null object reference
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
          at android.os.Handler.dispatchMessage(Handler.java:106)
          at android.os.Looper.loop(Looper.java:223)
          at android.app.ActivityThread.main(ActivityThread.java:7656)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
       Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.example.image_chan.core.SearchFormatter.FormatToTagsStr(java.lang.String)' on a null object reference
          at com.example.image_chan.Main.handleIntent(Main.java:102)
          at com.example.image_chan.Main.onCreate(Main.java:52)
          at android.app.Activity.performCreate(Activity.java:8000)
          at android.app.Activity.performCreate(Activity.java:7984)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601) 
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
          at android.os.Handler.dispatchMessage(Handler.java:106) 
          at android.os.Looper.loop(Looper.java:223) 
          at android.app.ActivityThread.main(ActivityThread.java:7656) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) 
  </code></pre>
  <p><strong>Code</strong></p>
  <p><strong>SearchFormatter.java</strong></p>
  <p>Located inside <code>app/core/SearchFormatter.java</code></p>
  <p>This also has another function that instead returns a String array.</p>
  <pre class="lang-java prettyprint-override"><code>package com.example.image_chan.core;
  
  import java.util.ArrayList;
  
  public class SearchFormatter {
      /*...*/
      public String FormatToTagsStr(String unformatted) {
          String lowCase = unformatted.toLowerCase();
          String[] unconvTags = lowCase.split(&quot;, &quot;);
  
          ArrayList&lt;String&gt; converted = new ArrayList&lt;String&gt;();
  
          for (String tag : unconvTags) {
              String trimmed = tag.trim();
  
              String formatted = trimmed
                      .replaceAll(&quot;\\s+&quot;, &quot;_&quot;)
                      .replaceAll(&quot;,&quot;, &quot;&quot;);
  
              converted.add(formatted);
          }
  
          return converted.toString();
      }
      /*...*/
  }
  </code></pre>
  <p><strong>Main.java</strong></p>
  <p>Located inside <code>app/Main.java</code></p>
  <p>The main activity file, the error is contained inside <code>handleIntent</code> which handles search queries using a search view.</p>
  <pre class="lang-java prettyprint-override"><code>package com.example.image_chan;
  /*...IMPORTS...*/
  
  public class Main extends AppCombatActivity implements GalleryFragment.GalleryListener {
      /*...*/
      private void handleIntent(Intent intent) {
          if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
              String query = intent.getStringExtra(SearchManager.QUERY);
              
              String convTags = formatter.FormatToTagsStr(query);
              System.out.println(convTags); // seems to be printing null
              
              // DefaultImageBoards.SAFEBOORU.search(int limit, String query)
              DefaultImageBoards.SAFEBOORU.search(100, convTags).async((List&lt;SafebooruImage&gt; images) -&gt; {
                  /*...*/
              }
          }
      }
      /*...*/
  }
  </code></pre>
  <p>I may be wrong here, but it seems it's returning an empty array or is it not initialized, is it true?</p>
  <p>Any help would be appreciated, thank you!</p>