DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004

    noSuchElement exception!!

    it is 4:30. i have been on this program since 6 yesterday afternoon!! help me fix this please!!

    it's a NoSuchElementException. so the string is null and it has to do with the nextToken() method.

    at java.util.StringTokenizer.nextToken(StringTokenizer.java:259)
    at BankDatabase.readFile(BankDatabase.java:26)
    at BankingSystem_hw7.main(BankingSystem_hw7.java:366)
    Exception in thread "main"
    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.

    when i was in the debugger, i noticed that in the FIRST LINE of the FOR LOOP, the value of inStr in the debugger was all in red. does that signify something?

    then, moving on, the first value that is tokenized is firstName. however, when i look up it's value, it says "10". what is going on there?

    public boolean readFile(String _dbFileName) throws FileNotFoundException, IOException
    // open the database file to read
    BufferedReader inFile = new BufferedReader (new FileReader (_dbFileName));
    String inStr = inFile.readLine();
    // the first line is the # of clients
    int N = Integer.parseInt(inStr);
    // the second line is the administration password
    adminPassword = inFile.readLine();
    clients = new Client[N];
    StringTokenizer strAnalyzer = new StringTokenizer(inStr, ",");
    for (int i = 0; i<N; i++)
    inStr = inFile.readLine();
    // fill the fields with the record
    String firstName = strAnalyzer.nextToken();
    String lastName = strAnalyzer.nextToken();
    String ssn = strAnalyzer.nextToken();
    String accNumber = strAnalyzer.nextToken();
    byte accType = Byte.parseByte(strAnalyzer.nextToken());
    byte accStatus = Byte.parseByte(strAnalyzer.nextToken());
    float accAmount = Float.parseFloat(strAnalyzer.nextToken());
    String pin = strAnalyzer.nextToken();
    // create new Client object
    clients[i]= new Client(firstName, lastName, ssn, accNumber,
    accType, accStatus, accAmount, pin);
    // close the input file
    return true;


  2. #2
    Join Date
    May 2004
    at BankDatabase.readFile(BankDatabase.java:26)
    So... what's at line 26 of BankDatabase.java? This is the first thing you should be looking at in all runtime errors.

  3. #3
    Join Date
    Feb 2004
    since you're instructor told you to use StringTokenizer you should stick with it, but I just thought i'd tell you that the StringTokenizer class is now deprecated. This means that it is only in the current library for backward compatibility, but Sun recommend not using it in any new code because it will likely be taken out of the library sometime in the future.

    Sun reccommends using the youString.split(aParameterToSplitOn) method. This method will split your string up on the specified parameter, and return the bits of your string in an array.
    String yourString = "a,b,c,d,e";
    String[] stringArray = yourString.split(",");
    This will produce an string array of length 5, and each index will contain one of the letters. The commas won't be in there at all because it removes them.

    If you want a better tutorial go see Cjards signature, he has a link something he wrote on the split() method on there.

    As to the question you asked, as Drain said you need to look at what is at line 26. The error message tells you exactly which line of your code the error was found at.

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.