Exception in thread "main" java.util.NoSuchElementException in my tokenizer class -


whenever run program gives me following error:

exception in thread "main" java.util.nosuchelementexception @ java.util.stringtokenizer.nexttoken(stringtokenizer.java:349) @ runcar.main(runcar.java:40) assignment says need close file, unsure on how so, , haven't found answers online.

here current code:

import java.io.ioexception; import java.util.stringtokenizer; import java.io.*;   public class runcar {      public static void main(string[] args) throws ioexception{          stringtokenizer tokenizer;         string line, code, file="car.txt";         double dealercost, price;         int idnumber, day, year, modelyear;         string makemodel, month, customer;         date datearrived, datesold;         car[] items = new car[13];         car[] placeholder = new car[1];          filereader fr = new filereader(file);         bufferedreader infile = new bufferedreader(fr);         int = 0;         line= infile.readline();         tokenizer = new stringtokenizer(line," ");         code = tokenizer.nexttoken();          while (code.charat(0)!='x'){             system.out.println();             system.out.println(line);             if (code.equals("c") || code.equals("c")){                 dealercost=double.parsedouble(tokenizer.nexttoken());                 idnumber=integer.parseint(tokenizer.nexttoken());                 month=(tokenizer.nexttoken());                 day=integer.parseint(tokenizer.nexttoken());                 year=integer.parseint(tokenizer.nexttoken());                 modelyear=integer.parseint(tokenizer.nexttoken());                 makemodel=(tokenizer.nexttoken());                 datearrived=new date(day, month, year);                 items[i]=new car(dealercost, idnumber, modelyear, datearrived,  makemodel);                 i++;             }//end "if c"             else if (code.equals("s1") || code.equals("s1"))             {                 idnumber=integer.parseint(tokenizer.nexttoken());                 price=double.parsedouble(tokenizer.nexttoken());                 month=(tokenizer.nexttoken());                 day=integer.parseint(tokenizer.nexttoken());                 year=integer.parseint(tokenizer.nexttoken());                 customer=(tokenizer.nexttoken());                 datesold=new date(day, month, year);                 (int j=0; j < items.length; j++)                 { if (idnumber==items[0].getidnumber())                     {   placeholder[0]=items[j];                         items[j]=new soldcar (placeholder[0].getdealercost(), placeholder[0].getidnumber(),                                               placeholder[0].getmodelyear(), placeholder[0].getdatearrived(),                                               placeholder[0].getmakemodel(), price, customer, datesold);                     }                              }                  i++;              }//end "if s1"             else if (code.equals("s2") || code.equals("s2"))             {                 dealercost=double.parsedouble(tokenizer.nexttoken());                 idnumber=integer.parseint(tokenizer.nexttoken());                 month=(tokenizer.nexttoken());                 day=integer.parseint(tokenizer.nexttoken());                 year=integer.parseint(tokenizer.nexttoken());                 modelyear=integer.parseint(tokenizer.nexttoken());                 makemodel=(tokenizer.nexttoken());                 datearrived=new date(day, month, year);                 price=double.parsedouble(tokenizer.nexttoken());                 month=(tokenizer.nexttoken());                 day=integer.parseint(tokenizer.nexttoken());                 year=integer.parseint(tokenizer.nexttoken());                 customer=(tokenizer.nexttoken());                 datesold=new date(day, month, year);                 items[i]=new soldcar(dealercost, idnumber, modelyear, datearrived,  makemodel,                                      price, customer, datesold);                 i++;              }//end "if s2"             else                 system.out.println ("error, wrong intital code. use c, s1, or s2.");                line= infile.readline();         }//end "while not x"          (int k=0; k < items.length; k++)             system.out.println(items[k] + "\n");                 }//ends main }//end class 

infile.close(); 

seems haven't looked hard enough: do need close() both filereader , bufferedreader?

here's link might help: bufferedreader documentation


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -