title: How to sort a large text file into a multi-dimensional array?
body: <p>I'm trying to read a large text file and sort it into a 3D array using scanner() but I don't think the array is being populated, and I keep getting the error <code>java.lang.NullPointerException</code>, but I suspect there is more going wrong than just that.</p>
  
  <p>I'm currently trying to use nested for loops to sort out the year, month, and each date.</p>
  
  <p>Another thing that I'd like to do is change the array from <code>String</code> to <code>int</code> but it's having none of it.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class GetData {
  
      public String[][][] sortedData;
  
      private Scanner rainFile;
  
      //method for opening the file
      public void openFile() {
  
          try{
              rainFile = new Scanner(new File("myfile.txt"));
          }
          catch(Exception e){
              System.out.println("Could not find file");
          }
      }
  
      //method for reading the file
      public void readFile(){
  
          int month = 0;
          int day = 0;
  
          //this loop sorts each year
          for(int l = 0; l &lt; 34; l++){
              String a = rainFile.next();
              sortedData[l][month][day] = a;
  
                  //this loop sorts every month of each year
                  for(int i = 0; i &lt; 12; i++){
                      String b = rainFile.next();
                      sortedData[l][i][day] = b;
                      month++;
  
                          //this loop sorts each individual entry of every month
                          for(int j = 0; j &lt; 31; j++){
                              String c = rainFile.next();
                              sortedData[l][i][j] = c;
                              day++;
                          }
                      }        
                  }
  
          }
  
          //close the file once it's been used
          public void closeFile(){
              rainFile.close();
          }
  
          //test method to see if array is full
          public void arrayTest(){
              System.out.print(sortedData[1][1][1]);
          }
  }
  </code></pre>
  
  <p>Many thanks.</p>