parsing - Input data: java.lang.NumberFormatException: For input string: "2 " -
here data text file:
21/08/12#ese-6329#pv/5732#30 27/08/12#pea-4567#pv/5732#3@ 11/09/12#ese-5577#xk/8536#2 14/09/12#pnw-1235#hy/7195#2@   and code form main method:
file orderdata = new file("purchaseorderdata.txt");             scanner datascan = new scanner(orderdata);  while(datascan.hasnextline()) {     string linedata = datascan.nextline();      scanner linescan = new scanner(linedata);     linescan.usedelimiter("#");      string date = linescan.next(); // line 259     string id = linescan.next();     string code = linescan.next();      string quantityplus = linescan.next();      if(!quantityplus.contains("@"))         management.addnewpurchaseorder(date, id, code,                                      integer.parseint(quantityplus)); // line 267     else     {         quantityplus = quantityplus.replace("@", "");         management.addnewpurchaseorder(date, id, code,                                     integer.parseint(quantityplus));         management.startnewmonth();     }   on first instance of
management.addnewpurchaseorder(date, id, code, integer.parseint(quantityplus));   i exception:
java.lang.numberformatexception: input string: "2 "     @ java.lang.numberformatexception.forinputstring(numberformatexception.java:65)     @ java.lang.integer.parseint(integer.java:580)     @ java.lang.integer.parseint(integer.java:615)     @ assignment2.maintest.main(maintest.java:267)   if do:
string quantityplus = linescan.next(); quantityplus = quantityplus.replace(" ", "");   i following:
java.util.nosuchelementexception java.util.nosuchelementexception     @ java.util.scanner.throwfor(scanner.java:862)     @ java.util.scanner.next(scanner.java:1371)     @ assignment2.maintest.main(maintest.java:259)   maintest.java:259 - string date = linescan.next();
i've tried use nextint() well, result same. wrong there? 
thanks lot!
maintest.java:259 - string date = linescan.next(); should check before if line not empty might why scanner throwing exception
Comments
Post a Comment