title: Null object reference error in java with char arrays
body: <p>I have a <code>char[]</code> that I am attempting to append values to. However, at the line <code>newStringAr[count] = ar[j][i]</code>, I am receiving an error:  <code>java.lang.NullPointerException: Attempt to invoke virtual method 'char java.lang.Character.charValue()' on a null object reference</code>. </p>
  
  <p>When I changed my array to a <code>Character[]</code>, this error was resolved, but then I was not able to convert my array to a string as shown in the last line of the code sample below. How can I resolve this issue?</p>
  
  <p>Note that <code>ar</code> is a previously-defined array of Characters (<code>Character[]</code> not <code>char[]</code>).</p>
  
  <pre><code>    int count = 0;
      char[] newStringAr = new char[ch.length];
  
      for (int i = 0; i &lt; ar.length; i++) {
          for (int j = 0; j &lt; ar.length; j++) {
              if (count&lt;ch.length) {
                  newStringAr[count] = ar[j][i];
                  count++;
              }
          }
      }
  
      String out = new String(newStringAr);
  </code></pre>