What is a NumberFormatException and how can I fix it?

前端 未结 9 1355
渐次进展
渐次进展 2020-11-21 04:25
Error Message:
Exception in thread \"main\" java.lang.NumberFormatException: For input string: \"Ace of Clubs\"
    at java.lang.NumberFormatException.forInputString         


        
9条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-21 04:44

    A NumberFormatException is the way Java has to say you "I tried to convert a String to int and I could not do it".

    In your exception trace you can read

    Exception in thread "main" java.lang.NumberFormatException: For input string: "Ace of Clubs"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
        at java.lang.Integer.parseInt(Integer.java:580)
        at java.lang.Integer.parseInt(Integer.java:615)
        at set07102.Cards.main(Cards.java:68)
    

    Basically, it means that at the line 68 of your code you call to the Integer.parseInt method passing "Ace of Clubs" as paremeter. This method expects a integer value represented as String, e.g. "4", so method complains throwing a NumberFormatException because "Ace of Clubs" does not seem a integer at all.

提交回复
热议问题