java - NoSuchElementException from reading from a file -


so i'm trying read first 4 variables each line in text file.

but catches nosuchelementexception.

public static void readrecords()     {         system.out.printf("%s%s%s%s" , "team id", "teamname","coachfirst", "coachlast");         try         {             while (input.hasnext())             {                 system.out.printf("%s%s%s%s",input.nextint(),input.next(),input.next(),input.next());              }          }         catch (nosuchelementexception statexception)         {             system.err.println("file improperly formed.");         }         catch (illegalstateexception stateexception)         {             system.err.println("error reading file");         }     } 

any ideas on why happening?

this text file elements:

teamnumber,team name,coach first,coach last,mentor first,mentor last,team fin sponsor,schools or sponsoring organization,tmmem1first,tmmem1last,tmmem2first,tmmem2last,tmmem3first,tmmem3last,tmmem4first,tmmem4last,tmmem5first,tmmem5last,tmmem6first,tmmem6last,tmmem7first,tmmem7last,tmmem8first,tmmem8last 6842,reagan ray-guns,judy,mallon,aziz,valdez,texas workforce commission,reagan h s,steven,cepeda,alan,yue,tim,callaway,damon,bertucci,samuel,de olvieira,samuel,day,,,, 6888,islanders,judy,maldonado,brady,trevino,three rivers robotics,three rivers middle,shireen,cowdrey,dee,roundtree,steven,callaway,francisco,bermea,,,,,,,, 7004,greenhill tops,kanat,labass,harvey,pflueger,greenhill boosters,greenhill school,harvey,pflueger,sandra,day,denny,rodriguez,shirley,couvillon,carly,szarka,,,,,, 

well, reading in 4 variables, each line in sample text file has more 4 entries (assuming using , scanner delimiter). means need call scanner#nextline() skip rest of input on line.

public static void readrecords() {     system.out.printf("%s%s%s%s" , "team id", "teamname","coachfirst", "coachlast");     try     {         while (input.hasnext())         {             system.out.printf("%s%s%s%s",input.nextint(),input.next(),input.next(),input.next());             input.nextline();  // skip remainder of line         }      }     catch (nosuchelementexception statexception)     {         system.err.println("file improperly formed.");     }     catch (illegalstateexception stateexception)     {         system.err.println("error reading file");     } } 

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 -