title: How do I fix Null Pointer Exception?
body: <p>I am trying to count the number of vowels in the string. The problem is that it compiles correctly, but when I run it the command window says "Exception in thread 'main' <em>java.lang.NullPointerException</em> at <em>CountVowels.main(<strong>CountVowels.java:25</strong>)</em>.</p>
  
  <pre><code>import javax.swing.JOptionPane;
  
  public class CountVowels
  {
      public static void main(String[] args)
      {
          String thingy = JOptionPane.showInputDialog("Please enter a sentence, and I  will count the vowels.");
          int count = 0;
  
          char[] chars = new char[thingy.length()];
          String[] letters = new String[thingy.length()];
  
          for(int i = 0; i &lt; thingy.length(); ++i)
          {
              chars[i] = thingy.charAt(i);
          }
  
          for(int i = 0; i &lt; letters.length; ++i)
          {
              letters[i].valueOf(chars[i]);
          }
  
          for(int i = 0; i &lt; chars.length; ++i)
          {
              if(letters[i].equals("a") || letters[i].equals("e") || letters[i].equals("i") || letters[i].equals("o") || letters[i].equals("u"))
              {
                  ++count;
              }
          }
          System.out.println("There are " + count + " vowels in the string + " + thingy);
      }
  }
  </code></pre>
  
  <p>What causes this, how can I fix it, and how can I prevent it from happening again in the future?</p>
  
  <p>line 25 is my if statement:</p>
  
  <pre><code>if(letters[i].equals("a") || letters[i].equals("e") || letters[i].equals("i") || letters[i].equals("o") || letters[i].equals("u"))
                  {
                      ++count;
                  }
  </code></pre>