DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    May 2008

    NoSuchElementException in Linux

    Greetings all. I have a rather interesting problem with the Scanner class, and Google hasn't been able to help.

    Some background: I just bought a new laptop for college and am dual-booting Linux and Vista (because it comes standard with Vista). On my old laptop I had XP, so I used that primarily for programming, but now that I have to have Vista I'm using mainly Ubuntu for coding.

    I transferred over my files and tried to execute one of my programs. The particular section giving the error is supposed to read in a configuration file ("config.inf") and set the look and feel and other options based on what it finds; the part of config.inf it's looking for comes after a '#' character, so it reads through until it gets there, reads the next line, and acts on that line's contents. On XP it works perfectly; on Ubuntu the Scanner class doesn't seem to want to work. This:
                Scanner in=new Scanner(new File("config.inf")).useDelimiter("\r|\r\n|\n");
                String temp="";
                //do stuff
                 catch(IOException io)
                //do other stuff
    returns a NoSuchElementException at the "temp=in.nextLine();" right after the while loop. I've tried to debug it and for some reason it thinks config.inf is empty; printing the value of temp has no effect because the while loop apparently never executes.

    My best guess was that the Windows line separator difference ("\r\n" instead of '\n') is the problem, so I set the Scanner to use both kinds of delimiters, but that didn't work. If that is the issue, and I just didn't fix it correctly, does anyone know how to fix that? If not, does anyone know what the problem actually is?

    Thanks in advance for your assistance.

  2. #2
    Join Date
    Jul 2005
    SW MO, USA
    What is the default operation of Scanner on Linux (without the useDelimiter)?
    What happens if Scanner doesn't find the file?
    Have you tried a simple program to read and display the file to see what is there on Linux?

  3. #3
    Join Date
    May 2008
    Quote Originally Posted by Norm
    What is the default operation of Scanner on Linux (without the useDelimiter)?
    So far as I know, the default operation is "Scanner works as intended." I added in the useDelimiter when I started having the problem, but I've tried nextLine() and next() both with and without it, to no effect. My high school had Linux in the computer science labs, and programming on those worked fine.

    What happens if Scanner doesn't find the file?
    Basically, in this particular class it sets the look and feel to the generic Java look and feel and sets a bunch of variables to 0 or null instead of their saved values. The program can function without inputting the saved values, I just want it to be able to save and retrieve them.

    Have you tried a simple program to read and display the file to see what is there on Linux?
    Yep; a program that reads in a short text file and prints it to System.out works fine. That's why I thought it was an issue with moving between OSs rather than a problem with Scanner.

Similar Threads

  1. Replies: 0
    Last Post: 07-21-2003, 02:17 PM
  2. Re: .Net and the Linux port
    By Elena in forum Careers
    Replies: 2
    Last Post: 07-10-2002, 11:40 PM
  3. My view of the world
    By Kevin Moore in forum .NET
    Replies: 55
    Last Post: 02-27-2002, 03:06 PM
  4. IBM & Linux
    By Robert Radina in forum Talk to the Editors
    Replies: 0
    Last Post: 06-15-2000, 07:28 AM
  5. Linux
    By Kevin Gadd in forum Talk to the Editors
    Replies: 3
    Last Post: 05-06-2000, 06:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.