This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes InputMismatchException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "InputMismatchException" Watch "InputMismatchException" New topic


Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129
I get an "InputMismatchException" from the following code

nextInt() is supposed to take that first '3' and pass it to 'quantity' but it isn't working. I don't really know what to ask. I'm hoping that someone will understand better what the exception means.
Joni Salonen
Ranch Hand

Joined: Jan 07, 2006
Posts: 53
After the call to nextDouble, the pointer is at the end of the line, before the line break. So when you call nextLine() it returns the string that is between that place and the next line break -- an empty string! Next you try to get numbers from the scanner but it sees the word "first" which of course can't be parsed as an int.
I agree. Here's the link:
subject: InputMismatchException
Similar Threads
Looping in exceptions
writing data to local file...while loop
Using Scanner to read one line at a time
Using Scanner to read one line at a time