在项目中通过String s=map.get(key);
得到s=""或者s=null
然后用Integer.parseInt(s)转化的时候却发现Integer.parseInt(s)无显示,也无报错信息;查了下API,里面没有给出String为null或者为""的返回值和异常...
非常郁闷中.....大家帮我解释下到底什么原因

解决方案 »

  1.   

    你看看其他问题
    没有反应
    代码执行到那儿了吗?  debug看看
      

  2.   

    public static int parseInt(String s)
                        throws NumberFormatException将字符串参数作为有符号的十进制整数进行解析。除了第一个字符可以是用来表示负值的 ASCII 减号 '-' ('\u002D') 外,字符串中的字符都必须是十进制数字。返回得到的整数值,就好像将该参数和基数 10 作为参数赋予 parseInt(java.lang.String, int) 方法一样。 参数:
    s - 包含要解析的 int 表示形式的 String。 
    返回:
    用十进制参数表示的整数值。 
    抛出: 
    NumberFormatException - 如果字符串不包含可解析的整数。
      

  3.   

    你自己写个main方法 试试就知道了 肯定报错
      

  4.   

    public static int parseInt(String s)
                        throws NumberFormatException
    Parses the string argument as a signed decimal integer. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign '-' ('\u002D') to indicate a negative value. The resulting integer value is returned, exactly as if the argument and the radix 10 were given as arguments to the parseInt(java.lang.String, int) method. Parameters:
    s - a String containing the int representation to be parsed 
    Returns:
    the integer value represented by the argument in decimal. 
    Throws: 
    NumberFormatException - if the string does not contain a parsable integer.
    你查的哪个API啊?????怎么可能没给出、、、、、、、、
    还有用的什么编译器,是不是它报错了你没发现、、、、、、
      

  5.   

    奇怪了,main方法是报错的,难道是map.get(key k);这个方法?
    这里是通过xml字符串解析得来的,里面有个节点就是<key></key>,中间是没有值的
      

  6.   

    应该是“在项目中通过String s=map.get(key);
    ”吧
      

  7.   

    会报NumberFormatException异常把!
      

  8.   


    Map接口中包含的“破坏性”方法可修改其所操作的映射,如果此映射不支持该操作,则指定这些方法抛出 UnsupportedOperationException。如果是这样,那么在调用对该映射无效时,这些方法可能,但并不一定抛出 UnsupportedOperationException。例如,如果某个不可修改的映射(其映射关系是“重叠”的)为空,则对该映射调用 putAll(Map) 方法时,可能但并不一定抛出异常在API上面找的...
      

  9.   

    jdk1.6.0-22 下
    String string="";
    System.out.println(Integer.parseInt(string));Exception in thread "main" java.lang.NumberFormatException: For input string: ""

    String string=null;
    System.out.println(Integer.parseInt(string));Exception in thread "main" java.lang.NumberFormatException: null
      

  10.   

    楼主你不会输出的是S吧 你的s的值是“”或null  而Integer.parseInt(string)) 确实会抛异常
      

  11.   

    楼主,既然你这个String会为空或者是空字符串,那么用Integer的这个方法可定会报java.lang.NumberFormatException错的啊还是看一下整个程序的业务逻辑为空时代表什么意思,然后控制一下这个情况吧。