title: java.lang.NumberFormatException for String to Int Java
body: <p>I have been searching for an answer to this, and I haven't been able to find someone who has rectified this quite yet.  I'm trying to populate an array, but check if it gets larger than a certain value.  However, when I run this, I get a Exception in thread "main" java.lang.NumberFormatException: For input string: "" Error.  Here is the code for it: </p>
  
  <pre><code>    public void setReadData() throws NoSuchElementException {
      try {
  
          for (int i = 0; i &lt; getRows(); i++) {
              String numbers = p.nextLine();
              String[] inputs = numbers.split(" ");
              if (inputs.length &gt; getCols()) {
                  System.out.println("There are more columns than the size specified!\n");
                  System.exit(1);
              }
              for (int j = 0; j &lt; getCols(); j++) {
                  int data = Integer.parseInt(inputs[j]);
                  this.setData(i,j,data);
              }
          }
  </code></pre>
  
  <p>And the error code is:</p>
  
  <pre><code>Exception in thread "main" java.lang.NumberFormatException: For input string: ""
  at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
  at java.lang.Integer.parseInt(Integer.java:504)
  at java.lang.Integer.parseInt(Integer.java:527)
  at foo.Bar.setReadData(Matrix.java:49)
  at foo.Bar.main(Matrix.java:226)
  </code></pre>
  
  <p>Any help is very much appreciated!</p>
  
  <p>----EDIT----</p>
  
  <p>To clarify, the old code that worked was:</p>
  
  <pre><code>for (int i = 0; i &lt; getRows(); i++) {
              p.nextLine();
              for (int j = 0; j &lt; getCols(); j++) {
                  this.setData(i,j,p.nextInt()); 
              }
  
          }
  </code></pre>
  
  <p>However, there is no checking that the whole line has been checked.</p>