File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
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
Rancher

Joined: Mar 22, 2005
Posts: 42952
    
  73
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.
 
Consider Paul's rocket mass heater.
 
subject: scanner NoSuchElementException