title: Java String.charAt() not working properly
body: <p>I'm trying to read in a grid from a text file to construct a graph out of it.</p>
  
  <p>Goal nodes are indicated by a <code>X</code> while other nodes are indicated by a <code>.</code>.</p>
  
  <p>I have the number of rows and the number of columns as well. So, I'm basically just trying to read in the next line for each row, then get the character at each column location by passing the iterator for column location and check it against an <code>X</code> to see if it should be marked as a goal node.</p>
  
  <pre><code>goalGraph = new int[rows][cols];
  for (int i = 0; i &lt; rows; i++) {
      String readLine = in.nextLine();
      System.out.println(readLine);
      for (int ii = 0; ii &lt; cols; ii++) {
          char c = readLine.charAt(ii);
          if (c == 'x') {
              goalGraph[i][ii] = 1;
          }
          else {
              goalGraph[i][ii] = 0;
              System.out.print(".");
          }
      }
  }
  </code></pre>
  
  <p>But I keep getting an <code>arrayoutofbounds</code> error at <code>index (0)</code>.</p>
  
  <p>Another strange thing is that it is not printing <code>readLine</code> when the lower code is implemented, but taking it out so it looks like:</p>
  
  <pre><code>goalGraph = new int[rows][cols];
  for (int i = 0; i &lt; rows; i++) {
      String readLine = in.nextLine();
      System.out.println(readLine);
      /**
      for (int ii = 0; ii &lt; cols; ii++) {
          char c = readLine.charAt(ii);
          if (c == 'x') {
              goalGraph[i][ii] = 1;
          }
          else {
              goalGraph[i][ii] = 0;
              System.out.print(".");
          }
      }
      **/
  }
  </code></pre>
  
  <p>As a result, the line being read in are printed, and I get the correct string:</p>
  
  <pre><code>X.....
  
  ...X..
  
  ......
  
  .X....
  </code></pre>
  
  <p>Can anyone point me in the right direction?</p>
  
  <p>Thanks!</p>