Results 1 to 2 of 2
  1. #1
    nicaskdjf is offline Member
    Join Date
    Feb 2011
    Rep Power

    Default nosuchelementexception

    public static void find(Scanner input, String phrase) {
    while (input.hasNextLine()) {
    String name =;
    if (name.toLowerCase().equals(phrase)) {

    i have this code and it does what it is supposed to and finds a name w/in a file, but then after it's found it it gives me the "NoSuchElementException".. how do i get rid of this? :confused:

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Rep Power


    If your input has the following "FredCRLF" the hasNextLine method returns true. The next method only consumes "Fred" leaving "CRLF" which hasNextLine returns true again. Then the next method tries to consume another token but there isn't one.

    Note: CRLF is carriage return/line feed.

Similar Threads

  1. Newbie JCreator NoSuchElementException Help!
    By Sly Cooper in forum JCreator
    Replies: 2
    Last Post: 12-18-2012, 06:44 PM
  2. Java Error: NoSuchElementException
    By xpngamer in forum New To Java
    Replies: 6
    Last Post: 03-19-2009, 08:37 PM
  3. Replies: 5
    Last Post: 02-27-2009, 06:19 AM
  4. Replies: 4
    Last Post: 06-08-2008, 03:19 PM
  5. Replies: 5
    Last Post: 05-14-2008, 02:43 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts