Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   NoSuchElementException (http://www.go4expert.com/forums/nosuchelementexception-t14478/)

cyrow 10Oct2008 14:40


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

class Sex{
        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")))
  book[a]= new Book(in.next(),in.next(),in.next(),in.next(),in.next(),in.next(),in.next());
  data = in.nextLine();


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 spaces. What could this problem be. How do I rectify it? I have been working on it for a very long time.

Dietel0004 Java How To Program c OUT Dietel & Dietel Prentice Hall 23-05-08 NULL
9Mec000980 Popular Mechanics r IN N/A N/A
MS00897666 Learn XP s IN George Gobin Microsoft
Lafore0037 Data Structures & Algorithms In Java c OUT Robert Lafore Sams 07-08-08
6Tech00472 Tech Magazine r IN N/A N/A

All times are GMT +5.5. The time now is 01:58.