Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I/O inputMismatchException  RSS feed

 
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
 
Bartender
Posts: 3316
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for updating the thread with your solution.
 
Marshal
Posts: 59124
180
  • 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?
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!