Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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: 3320
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for updating the thread with your solution.
 
Marshal
Posts: 60083
188
  • 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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!