NoSuchElementException? Need help please

my goal here is just to print something from my text file. Everything compiles but breaks down at runtime giving me the error :
Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken<StringTokenizer.java:332> at inventory.main<InventoryItem.java:30>
...I don't know, any ideas?
import java.util.*;
import java.io.*;
import java.lang.*;
     class Inventory
     public static void main(String[] args)
          final int MAX = 50;
          InventoryItem[] items = new InventoryItem[MAX];
          StringTokenizer tokenizer;
          String line;
          String name;
          String file = " inventory.txt ";
          int units = 0;
          int count = 0;
          float price;
          try
               FileReader fr = new FileReader ("inventory.txt");
               BufferedReader inFile = new BufferedReader(fr);
               line = inFile.readLine();
               while (line !=null)
                    tokenizer = new StringTokenizer (line);
                    name = tokenizer.nextToken();
                    try
                         units = Integer.parseInt(tokenizer.nextToken());
                         price = Float.parseFloat(tokenizer.nextToken());
                         items[count++] = new InventoryItem(name, units, price);
                    catch (NumberFormatException exception)
                         System.out.println("Error in input. Line ignored:");
                         System.out.println(line);
                    line = inFile.readLine();
               inFile.close();
               for (int i = 0; i<count; i++)
                    System.out.println (items.toString());
          catch (FileNotFoundException exception)
               System.out.println("The file " + file + " was not found.");
          catch (IOException exception)
               System.out.println("The file " + file + "was not found.");
     } //end of main method
}// end of Inventory class
public class InventoryItem
     private String name;
     private int units;
     private float price;
     public InventoryItem (String nameOfItem, int numOfUnits, float priceOfItem)
          name = nameOfItem;
          units = numOfUnits;
          price = priceOfItem;
     public String toString() {
          return name; // just trying to get the thing to print something...

see my other answer

Similar Messages

Maybe you are looking for

  • Retained a/c balance mismatch

    when I view the closing balance of Retained earning a/c for the year 2009 it is 14,78,900.  But when I view the opening balance of the same account in 2010, it gives another figure 12,60,991.  Why this is so.  The closing balance in the previous year

  • I was cheated by an authorized reseller

    i just bought a new iMac 2 hours ago the salesman said that this is the latest version of the iMac and no new version will be coming out soon but when i went back home and log into www.apple.com/my i found a new version of iMac !!!!!!! my godness....

  • My thread is ceated but doesn't have desired effect. Help?

    Basically I have a jDesktopPane wiith many jInternalFrames. I need each one to be its own thread so if one locks up the whole program doesn't crash. Right now it all works fine, but if you run a method on a huge file in a jInternalFrame it'll lock th

  • Uninstall/reinstall problems

    OK, I uninstalled iTunes, and now I want to reinstall it. I am trying to follow the directions from the Apple support site, but I cannot delete the C:\Program Files\iTunes folder. Every time I try to, I get a message saying "Cannot delete iTunes Help

  • Sharing between user log-ins

    Hello everyone - Yesterday my desktop icons and shortcuts magically disappeared as I was having some trouble opening Photoshop. I am able to open applications in OS9, but nothing running on OS10 will open. Interestingly enough, if I open Word using O