arrays - java.util.NoSuchElementException when looping to the second client -


new java , i'm tring create array of 5 client objects , pet object depending on amount in file specified. however, reads first client , pet info fine when next client gives me java.util.nosuchelementexception: null (in java.util.stringtokenizer).

import java.io.*; import java.util.*; /**  * write description of class vetclientdriver here.  *   * @author (anastasia)   * @version (4/19/15 --thpt4)  */ public class vetclientdriver {     /**      * constructor objects of class vetclientdriver      */     public static void main(string[] args) throws ioexception     {         string filename = ("c:\\users\\anastasia\\desktop\\clientdata.txt") ;         file file = new file(filename);         scanner fs = new scanner(file);         stringtokenizer stok = new stringtokenizer(fs.nextline(), ",|//");          vetclient []clients;         vetpets []pets;         string last, first, addr, id, num, balance;         string name,type,rabies,visit,weight;         string numofpets;         //fs = new scanner(file);          //stok = new stringtokenizer(fs.nextline(), ",|//");          clients = new vetclient[5];           for(int i=0; i<clients.length; i++)                      {                       last = stok.nexttoken();                      first = stok.nexttoken();                      addr = stok.nexttoken();                      id = stok.nexttoken();                      num = stok.nexttoken();                      balance = stok.nexttoken();                      numofpets = stok.nexttoken();                       clients[i] = new vetclient(last,first,addr,id,num,balance,numofpets);                      system.out.println(clients[i].clientinfo());                      pets = new vetpets[integer.parseint(numofpets)];                       for(int k=0; k<pets.length; k++)                         {                         stok = new stringtokenizer(fs.nextline(), ",|/");                        name = stok.nexttoken();                        type = stok.nexttoken();                        weight = stok.nexttoken();                        rabies = stok.nexttoken();                        visit = stok.nexttoken();                        pets[k] = new vetpets(name,type,weight,rabies,visit);                        system.out.println(pets[k].petinfo() + "\n");                          }                         }                      fs.close();                     }                   }       

add following line in loop

 stringtokenizer stok = new stringtokenizer(fs.nextline(), ",|//"); 

note :first remove above line current position


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -