2014-09-30 33 views
0
Exception in thread "main" java.lang.NumberFormatException: For input string: "64403F " 
    at java.lang.NumberFormatException.forInputString(Unknown Source) 

但它適用於許多輸入,如A89B88,927F66,FFDB58。你能幫我理解這裏發生的事情嗎?Integer.decode(String s)爲某些字符串拋出NumberFormatException

+2

這些都不例子作品,如果你不加'0x'他們(例如,'0xA89B88 ')。 – Tom 2014-09-30 21:49:00

回答

0

您的String即投擲NumberFormatException結束於空白"64403F "。在解析之前,請致電String上的trim()。使用Integer.parseInt(String, int)

String str = "64403F "; 
System.out.println(Integer.parseInt(str.trim(), 16)); 

或者,使用Integer.decode(String)

String str = "64403F "; 
System.out.println(Integer.decode("0x" + str.trim())); 

輸出是

6570047 
相關問題