• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception in thread "main" java.util.InputMismatchException  RSS feed

 
john bullwinkle
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm unsure of why i'm getting this error. from the text file i'm readin in, the places all match up, so i'm not sure what's throwing it off. here is my code



here is the text file i'm reading

1,LP Carbon Monoxide Call Form,LPCarbonMonoxideCallForm_distributed,Salesman Number-Tank Description-Other Item,CrbnMonCall,
1,Driver Vehicle Inspection Report,DriverVehicleInspectionReport_distributed,Salesman Number-Tank Description-Other Item,DrvrVehInspct,
1,LP Driver Sales Hours Record,LPDriverSalesHoursRecord_distributed,Salesman Number-Tank Description-Other Item,DrvSlsHrs,
1,LP Equipment Calibration Form,LPEquipmentCalibrationForm_distributed,Salesman Number-Tank Description-Other Item,LPEqpmntCalbrt,
1,LP Equipment Lease,LPEquipmentLease_distributed,Salesman Number-Tank Description-Other,ItemLPEqpLse,
1,LP Montly Sales Checklist For Service Techs,LPMonthlySalesChecklistForServiceTechs_distributed,Salesman Number-Tank Description-Other Item,MthlSlsChkLstTch,
1,LP Out of Gas Form,LPOutOfGasForm_distributed,Salesman Number-Tank Description-Other Item,OutGas,
1,LP Tank Cart Inspections,LPTankCartInspections_distributed,Salesman Number-Tank Description-Other Item,TnkCrtInsp

here is the error log:

monthlyOrDaily = 1
formDisplayName =LP Carbon Monoxide Call Form
formFileName = LPCarbonMonoxideCallForm_distributed
formSaveOptions = Salesman Number-Tank Description-Other Item
endFileName = CrbnMonCall
a = 0
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)
at java.util.Scanner.nextInt(Scanner.java:2050)
at servicetech.SelectionScreen.formFileReader(SelectionScreen.java:265)
at servicetech.Main.main(Main.java:41)

 
Steve Harney
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looking at the stack

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:840)
at java.util.Scanner.next(Scanner.java:1461)
at java.util.Scanner.nextInt(Scanner.java:2091)

and the definition.
Thrown by a Scanner to indicate that the token retrieved does not match the pattern for the expected type, or that the token is out of range for the expected type.

It means that your program has tried to read a value that is an integer that is not an integer.

I really havnt used the scanner but looking at the API i would suspect that its reading a empty string off the end of the first line and cannot form it into a number.
you may consider calling the nextLine() on your scanner after the end of each line.

Steve


 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a comma at the end of the line. That means Scanner will assume there is something after the comma, in this case an empty String. It is impossible to get an int out of an empty String, so you get the exception.
I think Steve Harney's diagnosis and prescription are correct. Try an additional nextLine() , or next() call, but nextLine() is probably correct.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!