本帖最后由 沈子豪 于 2013-3-15 22:17 编辑
public class StringBufferDemo{ public static void main(String[] args) { // 方式1 int x = 10; Integer i = new Integer(x); System.out.println("i:" + i); // 方式2 //String s = "10"; String s = "a"; Integer ii = new Integer(s); System.out.println("ii:" + ii); } } 运行结果如下Exception in thread "main" java.lang.NumberFormatException: For input string: "a" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:492) at java.lang.Integer.<init>(Integer.java:677) at test1_1.StringBufferDemo.main(StringBufferDemo.java:13) 我查了下异常显示如下 public Integer(String s) throwsNumberFormatException { this.value = parseInt(s, 10); },哪位大神能解释下?
|