jQuery in Action, 3rd edition
The moose likes I/O and Streams and the fly likes scanner NoSuchElementException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "scanner NoSuchElementException " Watch "scanner NoSuchElementException " New topic

scanner NoSuchElementException

Yon Wolf

Joined: May 25, 2014
Posts: 1
Hi...I'm trying to write this Blackjack program that runs until the user runs out of money. So the game has to run multiple times. My problem is, the Scanner only works in the first loop and then throws an exception the second time (on int wager=scan.nextInt();)! How can I get the Scanner to contnue taking inputs? (incomplete program shown)

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Welcome to JavaRanch.

You should generally call any of the "hasNextXYZ()" methods before getting the next element. Working through http://www.coderanch.com/how-to/java/UserInput would also be helpful.
I agree. Here's the link: http://aspose.com/file-tools
subject: scanner NoSuchElementException
It's not a secret anymore!