title: Why is this returned array not working?
body: <p>In this code I'm trying to pass a two dimensional array of chars into cArray and return a one dimensional array of elements that display a string of each row of the two dimensional array.</p>
  
  <p>Example:</p>
  
  <p>Input array (two dimensonal):</p>
  
  <blockquote>
    <p>'a' 'b' 'c' 'd'</p>
    
    <p>'e' 'f' 'g' 'h'</p>
    
    <p>'i' 'j' 'k' 'l'</p>
  </blockquote>
  
  <p>Returned array (one dimensional): </p>
  
  <blockquote>
    <p>abcd</p>
    
    <p>efgh</p>
    
    <p>ijkl</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <p>Main:</p>
  
  <pre><code>public class hw2p1
  {   
     public static void main (String [] args) 
     {
  
    // declare and initialize array of chars
    char[][] array = { {'a', 'b', 'c', 'd'},
                       {'e', 'f', 'g', 'h'},
                       {'i', 'j', 'k', 'l'} };
  
    cArray array1 = new cArray(array); 
  
    String[] array2 = array1.getArray();
  
    for (int i=0; i&lt;array2.length; i++) 
      System.out.println(i+" "+array2[i]);
  
  
    }
  }
  </code></pre>
  
  <p>cArray:</p>
  
  <pre><code>public class cArray
  {   
  
     private String[] newArray;
  
     public cArray ( char[][] array2 )
     {  
        String[] newArray = new String[array2.length];
  
        for (int i=0; i &lt; array2.length; i++)
           newArray[i] = String.valueOf(array2[i]);
  
        for (int l=0; l &lt; array2.length; l++)
           System.out.println(newArray[l]);
  
  
  
     }
     public String[] getArray()
     {
        return newArray;
     }
  }
  </code></pre>
  
  <p>I get this error when I try to run this:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.NullPointerException     at
    hw2p1.main(hw2p1.java:16)</p>
  </blockquote>
  
  <p>Sorry if this is an obvious error. I'm very new to programming. Thank you for any help!</p>