• Post Reply Bookmark Topic Watch Topic
  • New Topic

No such element exception  RSS feed

 
M Donaldson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


These are the errors I am getting

java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at atmInterface.atmGUI(atmInterface.java:13)
at test_Class.main(test_Class.java:9)
 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please start by first understanding how you can use Scanner utility. I think you are using it in an improper manner.

Not sure about the pattern I see in this program. Somehow it reminds me of how I used to write C++ code.
 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found this online and this looks useful for your case.

Check this: NoSuchElementException
 
M Donaldson
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought that might have been an issue.

All I want to do is collect two different user inputs from this class. Can i use one line of code
Scanner scan01 = new Scanner(System.in);

Or do I have to have this line with a different variable for each user input?
Scanner scan01 = new Scanner(System.in);
Scanner scan02 = new Scanner(System.in);
 
s ravi chandran
Ranch Hand
Posts: 579
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A single scanner would solve your purpose. And you can even close it when you are done.

When I used to write such programs in c++, I used to put the questions in a for loop and kept an option to exit the loop. This way user would always see a main menu and keep selecting some option till be was done and selected option to exit.
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
s ravi chandran wrote:And you can even close it when you are done. 

Except when you open Scanner with System.in.  Then never close it.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have variables for: deposit, Withdrawal, and checkBal, each local to the blocks they're in. That means they aren't talking to each other. Seems to me that you'd want checkBal to be a class member variable (i.e. field) that the various operations utilize.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!