I want to keep taking input until the letter q is typed. If the letter is not q I pass it to an object from a class I created. This object will take input from the user before returning to the calling class (sorry for bad terminology)
Here's what I've tried:
String in;
while(true)
{
System.out.println("a:");
System.out.println("b");
System.out.println("q - quit");
try{
in = input.next();
}catch(NoSuchElementException name)
{
//do nothing
}
if(in.equals("q"))
System.exit(0);
component.inputted(in);
}
I get this after the first iteration:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at CheckerBoardComponents.inputed(CheckerBoardComponents.java:109)
at CheckerBoardViewer.main(CheckerBoardViewer.java:37)
I'd like to use scanner to take input, so please don't tell me that I should be using something else unless it will be really important