title: Java- Array Index Out of Bounds Exception
body: <p>I'm making a simple program where I input 20 integer values from a text file into the 2D array.
  I obtained the row and column value through the first two values in the text file.  </p>
  
  <p>From what I understand, the <code>IndexOutOfBoundsException</code> means that my 2D array (4 rows and 5 columns): </p>
  
  <ol>
  <li>the values are larger than the array size- not possible because
  there are only 20 values. </li>
  <li>there are not enough values to fill the
  array- ^ reason</li>
  </ol>
  
  <p>What am I missing? <code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0</code></p>
  
  <pre><code>public class Practice {
  
  public static void main(String[] args){
      int[][] thisArray=fillArray(args[0]);
      print(thisArray,thisArray.length);
  }
  
  public static int[][] fillArray(String myFile){
      TextFileInput in= new TextFileInput(myFile);
      String r=in.readLine();//4 rows
      String c=in.readLine();//5 columns
      int row=Integer.parseInt(r);//parse from string to int
      int col=Integer.parseInt(c);
      int[][] tempArray=new int[row][col];
  
      for(int fillRow=0; fillRow&lt;row;fillRow++){
          for(int fillCol=0; fillCol&lt;col;fillCol++){
              String temp= in.readLine();
              tempArray[fillRow][fillCol]=Integer.parseInt(temp);
          }
      }
      return tempArray;//return 2D array
  }
  
  public static void print(int[][] array,int length){
      for(int r=0;r&lt;length;r++){
          for(int c=0;c&lt;array[r].length;c++){
              System.out.print(array[r][c]);
          }
          System.out.println();
      }
  }
  }
  </code></pre>
  
  <p>textfile:(1 number per line)
  4
  5
  1
  3
  5
  7
  12
  34
  56
  78
  21
  44
  36
  77
  29
  87
  48
  77
  25
  65
  77
  2</p>