Cannot assign string from array to the int
<p>I have written the following line of code that reads the data in a text file and stores it in a array. Everything works fine except for when I try and convert the <code>String</code> into <code>int</code>. </p>

<p>Here I am trying to scan the text file line by line and store every word separated by comma in an array. I cant figure out why its throwing <code>NumberFormatException</code> when I convert <code>String</code> into <code>int</code> and assign it to <code>int id</code>. </p>

<p>The following is the code I have written:</p>

<pre><code>public boolean loadPapers(){
    String fileName = "paper.txt"; // file to be opened
    boolean fileOpened = true;
    int id, rank;
    String topic, author, date;

    try {
        Scanner fileData = new Scanner(new File(fileName));

        while(fileData.hasNextLine()){
            String line = fileData.nextLine();

            String[] words = line.split(","); // Separate words from sentence


            // get required parameters for Paper object
            id = Integer.parseInt(words[0]);  // throws numberFormatException
            topic = words[1];
            author = words[2];
            date = words[3];
            rank = Integer.parseInt(words[4]);  // throws numberFormatException

            // create new paper
            Paper entry = new Paper(id, topic, author, date, rank);
            paperList.add(entry);

        } // end while

        fileData.close(); // close file
    }  // end try

    catch (FileNotFoundException e) {
        fileOpened = false;
        swingErrorMessage("ERROR: File couldn't be opened.\nNo papers were loaded.", "File Error");
    } // end catch

    return fileOpened;

} // end loadPapers
</code></pre>

<p>The following is the content of text file:</p>

<pre>
46,Evolutionary Comp,Michael Smith,12/01/10,4
61,Fuzzy Logic and App,John Peterson,13/01/10,3
118,Neural Networks,Arthur London,20/01/10,5 
200,Evolutionary Comp,Scott Jones,30/01/10,1 
210,Fuzzy Logic and App,Joe Wang,01/02/10,4 
12,Evolutionary Comp,Andy Roberts,12/12/12,3 
123,Computer Science,Zhou You,12/12/12,3
</pre>

<p>The line that program fails on is:</p>

<pre><code>id = Integer.parseInt(words[0]);  // throws numberFormatException
</code></pre>

<p>The error message looks like:</p>

<pre><code>Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:470)
at java.lang.Integer.parseInt(Integer.java:499)
at PaperManagerApplication.Frame.loadPapers(Frame.java:409)
at PaperManagerApplication.PaperManager.main(PaperManager.java:16)
</code></pre>
