NoSuchElementException

Discussion in 'Java' started by cyrow, Oct 10, 2008.

  1. cyrow

    cyrow New Member

    Joined:
    Nov 19, 2007
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    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")))
    {
       //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 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
    END
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice