Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

What?! This compiled ok earlier!

Options
  • 14-02-2006 11:57pm
    #1
    Registered Users Posts: 3,579 ✭✭✭


    I'm no Java guru, but if something compiles on one machine wtith no exceptions thrown, but when compiled on another (my home machine) with this:
    Exception in thread "main" java.util.NoSuchElementException: No line found
            at java.util.Scanner.nextLine(Scanner.java:1471)
            at GMLtoVRML.main(GMLtoVRML.java:156)
    

    What the hell is happening?

    Different version of SDK or something?

    The line 156 is just:
    line = in.nextLine();
    
    Where "in", is a Scanner.

    The program has that at the end of a while loop (just before the closing bracket), that runs a few hundred times, and it worked grand earlier, why's it throwing this exception! :confused:
    I tried compiling it the normal way within a command console (XP), and also using the built in one in TextPad 4.


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    The Scanner class was only introduced in Java5, so it won't be present in a 1.4 JDK.


  • Registered Users Posts: 3,579 ✭✭✭BopNiblets


    But I have jdk1.5.0_05!

    It also runs through the while loop a few times and then for the hell of it (I tested this by putting a System.out.println("working!"); before it), throws that exception.

    I also put in a num++; thing to see how many times it runs, and it gives up after 14500, it should be around 29000 or so. :(


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    is there actually a "nextline" for sure? Can you run something like this:

    if(scanner.NextLineExists)
    {
    scanner.readline();
    }


  • Registered Users Posts: 1,481 ✭✭✭satchmo


    Are you sure you gave the version at home the exact same input file as the other one?


  • Registered Users Posts: 19,396 ✭✭✭✭Karoma


    i'm tired but...

    java -version to check that it is indeed referencing 1.5 and not an older version (PAth/registry issue)

    With that ruled out - how are you iterating? How/Are you checking against .hasNext()?
    This error is quite common when a loop/iteration is checking for number of elements != number of expet elements (i.e. -1, or 0 (empty file/incorrect file specified -i'm sure you have checked/try{catch properly opening the file..)..) - usually a result of the loop specified.. Post up more of the code perhaps?


  • Advertisement
  • Registered Users Posts: 3,579 ✭✭✭BopNiblets


    I have java version "1.5.0_06", and the input files are identical (checked with TextPads "Compare Files" feature)

    Looking through it again, the only thing I can think it might be is that I have two assignments of the String line = in.nextLine();
    One declaring the String and assigning (above, just after opening the while() ) and the other just before closing the while loop.

    That shouldn't matter though, you're allowed assign variables more than once, right?!

    Anyway, I took the 2nd one out, and it seems to be compiling properly... for now!
    Still, strange about different compiling on two machines that definately have Java 5.
    Thanks for the help guys.


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    can you post the code snippet of the changes.


  • Closed Accounts Posts: 888 ✭✭✭themole


    BopNiblets wrote:
    Looking through it again, the only thing I can think it might be is that I have two assignments of the String line = in.nextLine();
    One declaring the String and assigning (above, just after opening the while() ) and the other just before closing the while loop.

    That shouldn't matter though, you're allowed assign variables more than once, right?!

    yes, but if you are declaring them twice, one inside the while loop and one outside then they are two different variables, dunno if this would affect the code you have written, but just be aware of that


Advertisement