GeeCON Prague 2014*
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
Author

scanner NoSuchElementException

Yon Wolf
Greenhorn

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
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
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.


Ping & DNS - my free Android networking tools app
 
GeeCON Prague 2014
 
subject: scanner NoSuchElementException