• Post Reply Bookmark Topic Watch Topic
  • New Topic

I/O inputMismatchException  RSS feed

 
Akimbas Akimbasas
Ranch Hand
Posts: 32
1
  • Mark post as helpful
  • send pies
  • 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
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for updating the thread with your solution.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!