title: How to store data read from a file into 2D array
body: <p>I'm currently working with my assignment which requires me to read input from a text file and store into a matrix. Basically I have part of my code here.</p>
  
  <pre><code>    int count = 0 ;
      double[][] matrix = null;
  
      while ((line = reader.readLine()) != null) 
      {   
          line2 = line.split(" ");
  
          double[] criteriaWeight = {Double.parseDouble(line2[0]),Double.parseDouble(line2[1]),Double.parseDouble(line2[2]),Double.parseDouble(line2[3])};
  
          for ( int i = 0 ; i &lt; criteriaWeight.length ; i++ )
              matrix[count][i] = criteriaWeight[i];
  
          count++;
      }
  </code></pre>
  
  <p>Now, the logic of what I'm trying to do is that I read data from a text file and then convert it into a <code>double</code> and store into a 2D array (<code>matrix</code>). I managed to read the data from the file. That is error-free.</p>
  
  <p>Now, my problem is at the <code>matrix[count][i] = criteriaWeight[i];</code> where I get error </p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
  at javaapplication2.JavaApplication2.readFile(JavaApplication2.java:42)
  at javaapplication2.JavaApplication2.main(JavaApplication2.java:56)
  Java Result: 1
  </code></pre>
  
  <p>Anyone can point to my mistakes here? Thank you very much.</p>