• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

I/O inputMismatchException

 
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to read information from a file, that contains information, structured like this:

2;Xbox 360;London;Black;Male;
1;Playstaion 3;Paris;Red;Female;
9;Playstaion 3;Moscow;White;Female;

I use ";" as delimiter for Scanner.. All the variables to store the tokens are Strings, except the first which is int type.

The problem is, that the first line is read with no problems, but immediately after the second one, I get inputMismatchException and if I try to System.out.println(ex.getMessage()); I get "null".
So I guess Scanner doesn't find the int, what could be the problem ?



Fixed the problem by adding sc.newLine() at the end of while loop
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for updating the thread with your solution.
 
Marshal
Posts: 80645
473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done
Do you understand why it worked? Have you considered that changing the delimiter might be a better solution?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic