开发者

What does InputMismatchException Mean?

Exception in thread "main" java.util.InputMismatchException

What it indicates for me while I'm using it with scanner class? Complete stacktrace is

Exception in thread "main" java.util.InputMismatchException
        at java.util.Scanner.th开发者_JAVA百科rowFor(Unknown Source)
        at java.util.Scanner.next(Unknown Source)
        at java.util.Scanner.nextInt(Unknown Source)
        at java.util.Scanner.nextInt(Unknown Source)
        at ParseString.main(ParseString.java:9)


Please see the docs at the JavaDoc.

The answer should be clear:

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.


From the docs:

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.

So maybe you've called nextInt but the next token is "1.5" or "foo". You should look at the stack trace to see exactly which Scanner call caused the problem, and then work out what the token actually was, and how you want to handle that sort of failure.


You should read the according javadoc (for example: http://download.oracle.com/javase/1,5.0/docs/api/java/util/Scanner.html ). The Exception is raised if the input does not match the method you used to get it, for example you use getBoolen but the next value can not be translated into a boolean.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜