Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

NoSuchElementException



import java.util.*;
import java.io.*;

class Test{
public static void main(String[] args)throws IOException{
Book[]book = new Book[10];

Scanner in = new Scanner(new FileReader("love.txt"));
String data;


int a = 0;
data = in.nextLine();
while (!(data.equals("END")))
{
   //System.out.println(data);
  
   book[a]= new Book(in.next(),in.next(),in.next(),in.next(),in.next(),in.next(),in.next());
   a++;
  
   data = in.nextLine();
}
in.close();
}
}

I can read the file a line at a time, but when I try to parse it, it generates the NoSuchElementException. The elements in the file is separated by tabs. What could this problem be. How do I rectify it? I have been working on it for a very long time.