java - Cant understand why this doesn't print to the text file -


im coding hotel reservation program , im using gui input guests info textfields. have array these input values should go straight (maybe thats problem, donno how fix it). after want values in array print text file had created. heres code:

guests[] garr = new guests[1000];    public static dateformat dateformat = new simpledateformat("dd/mm/yyyy hh:mm");    public int cnt = 1;    int count = 0;    string firstname ;    string lastname;    string country ;    string idtype;    string passportno ;    string idno ;    string addr1;    string addr2 ;    int areacode ;    string telno ;    string cellno ;    string email ; 

first have declared these variables global (these variables in object class guests) put them again in jframe class called home. after have made these variables take value of textfields have text input them. within method checks see if fields blank:

public collection<string> getnonblankfields()  {     this.firstname = namef.gettext();     this.lastname = namel.gettext();     this.country = countr.gettext();    this.idtype = idty.gettext();     this.passportno = passno.gettext();     this.idno = idnumber.gettext();     this.addr1 = add1.gettext();     this.addr2 = add2.gettext();     int areacode = integer.parseint(area.gettext());     this.telno = tel.gettext();     this.cellno = cell.gettext();     this.email = em.gettext();      this.nonblankfields = new arraylist<string>();     this.nonblankfields.add(this.firstname);     this.nonblankfields.add(this.lastname);     this.nonblankfields.add(this.country);     this.nonblankfields.add(this.idtype);     this.nonblankfields.add(this.passportno);     this.nonblankfields.add(this.idno);     this.nonblankfields.add(this.addr1);     this.nonblankfields.add(this.addr2);     this.nonblankfields.add(this.telno);     this.nonblankfields.add(this.cellno);     this.nonblankfields.add(this.email);     system.out.println(this.nonblankfields);     return this.nonblankfields; } 

last thing printing file (this major problem) ive tried many things fix surpasses code , goes straight catch:

     file gfile = new file("c:\\users\\gordy\\dropbox\\it\\hotel reservation\\hotel\\src\\reservation\\guests.txt"); try {             if (!gfile.exists()) {                 gfile.createnewfile();             }                  string delim = "#";                string firstname = namef.gettext();                     stringtokenizer stk = new stringtokenizer(delim);                     firstname += stk.nexttoken();                     system.out.print("fname = " + firstname);                     lastname += stk.nexttoken();                     system.out.print("lastname= " + lastname);                     country += stk.nexttoken();                     system.out.print("country= " + country);                     idtype += stk.nexttoken();                     idno += stk.nexttoken();                     addr1 += stk.nexttoken();                     addr2 += stk.nexttoken();                     areacode += integer.parseint(stk.nexttoken());                     telno += stk.nexttoken();                     cellno += stk.nexttoken();                     email += stk.nexttoken();                     garr[count] = new guests(firstname, lastname, country, idtype,  idno,addr1,addr2, areacode, telno, cellno, email);                     printwriter pw=new printwriter(new filewriter (gfile,true));                     pw.println(garr[count]);                     count++;                     pw.close();                     checkin.hide();                     home.this.setvisible(true);             }          catch (exception e) {             system.out.print("this did not work heres error: " + e);         } 

would love use stringtokenizer print # in between data on 1 line.

this whole error:

    java.util.nosuchelementexception @ java.util.stringtokenizer.nexttoken(stringtokenizer.java:332) @ reservation.home.jbutton8actionperformed(home.java:1657) @ reservation.home.access$100(home.java:29) @ reservation.home$2.actionperformed(home.java:269) @ javax.swing.abstractbutton.fireactionperformed(abstractbutton.java:1995) @ javax.swing.abstractbutton$handler.actionperformed(abstractbutton.java:2318) @ javax.swing.defaultbuttonmodel.fireactionperformed(defaultbuttonmodel.java:387) @ javax.swing.defaultbuttonmodel.setpressed(defaultbuttonmodel.java:242) @ javax.swing.plaf.basic.basicbuttonlistener.mousereleased(basicbuttonlistener.java:236) @ java.awt.component.processmouseevent(component.java:6263) @ javax.swing.jcomponent.processmouseevent(jcomponent.java:3267) @ java.awt.component.processevent(component.java:6028) @ java.awt.container.processevent(container.java:2041) @ java.awt.component.dispatcheventimpl(component.java:4630) @ java.awt.container.dispatcheventimpl(container.java:2099) @ java.awt.component.dispatchevent(component.java:4460) @ java.awt.lightweightdispatcher.retargetmouseevent(container.java:4574) @ java.awt.lightweightdispatcher.processmouseevent(container.java:4238) @ java.awt.lightweightdispatcher.dispatchevent(container.java:4168) @ java.awt.container.dispatcheventimpl(container.java:2085) @ java.awt.window.dispatcheventimpl(window.java:2478) @ java.awt.component.dispatchevent(component.java:4460) @ java.awt.eventqueue.dispatchevent(eventqueue.java:599) @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:269) @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:184) @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:174) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:169) @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:161) @ java.awt.eventdispatchthread.run(eventdispatchthread.java:122) 

you calling stk.nexttoken() multiple times, object holds single "#". means can call nexttoken() on once. integer.parseint("#") throws exception. suggest doing :

don't add "#" , instead tostring() method in guests like

public string tostring() {     return firstname + "#" + lastname + "#" + ... + "#" + email; } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -