Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's the definition of <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/InputMismatchException.html" rel="nofollow">InputMismatchException</a>:</p> <blockquote> <p>Thrown by a Scanner to indicate that the token retrieved does not match the pattern for the expected type, or that the token is out of range for the expected type.</p> </blockquote> <p>I scanned through your code, and it seems like <code>menuChoice = sc.nextInt();</code> might be the one that throws that exception. Chances are your <code>while loop</code> is looping too many times and your scanner doesn't have the next int value to read, which is the reason you get this exception.</p> <p><code>nextInt()</code> is the only Scanner API you used that throws this particular exception. Here's the documentation of <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html#nextInt%28%29" rel="nofollow">nextInt()</a>:-</p> <pre><code>public int nextInt(int radix) Scans the next token of the input as an int. This method will throw InputMismatchException if the next token cannot be translated into a valid int value as described below. If the translation is successful, the scanner advances past the input that matched. If the next token matches the Integer regular expression defined above then the token is converted into an int value as if by removing all locale specific prefixes, group separators, and locale specific suffixes, then mapping non-ASCII digits into ASCII digits via Character.digit, prepending a negative sign (-) if the locale specific negative prefixes and suffixes were present, and passing the resulting string to Integer.parseInt with the specified radix. Parameters: radix - the radix used to interpret the token as an int value Returns: the int scanned from the input Throws: InputMismatchException - if the next token does not match the Integer regular expression, or is out of range NoSuchElementException - if input is exhausted IllegalStateException - if this scanner is closed </code></pre> <p><strong>EDIT:</strong></p> <p>Try changing your while loop to be the following:-</p> <pre><code>while(menuChoice != 0 &amp;&amp; sc.hasNext()){ ... } </code></pre> <p>This should fix your problem.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload