What is a NumberFormatException and how can I fix it?

前端 未结 9 1318
渐次进展
渐次进展 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:42

    The Exception comes in your code, where you convert the String to an Integer :

    int first_value = Integer.parseInt(cards[index]);
    

    where you pass a String as "Ace of Clubs" which is not possible to convert as integer,so it throws Number Format Exception. You can use,

    try {
         ....
         // Your Code
         ....
        }
    catch(NumberFormatException e)
    {
        e.getMessage();  //You can use anyone like printStackTrace() ,getMessage() to handle the Exception
    }
    

提交回复
热议问题