// 转换错误,下面会出现 java.lang.ClassCastException错误,改用int iInc = Integer.parseInt(m.get("INCREMENTVAL").toString());
// 1 int iInca = Integer.valueOf((String) m.get("INCREMENTVAL")).intValue();

// 2 int iInc = Integer.parseInt(m.get("INCREMENTVAL").toString());第一句,在main方法测试没有问题不会出现异常讲讲两句的区别,还有为什么第一局回出现异常

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【leomei001】截止到2008-07-28 09:58:37的历史汇总数据(不包括此帖):
    发帖的总数量:0                        发帖的总分数:0                        每贴平均分数:0                        
    回帖的总数量:0                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:0                        结贴的总分数:0                        
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:---------------------结分的百分比:---------------------
    无满意结贴率:---------------------无满意结分率:---------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    cast异常只能你转换的过程中类型不匹配,也就是没有继承,或者实现同一接口等关系..
    public static Integer valueOf(String s) throws NumberFormatException
        {
    return new Integer(parseInt(s, 10));
        }这个是valueOf方法,第一句话中,它在parseInt的时候传了第2个参数,会将这个字符串转换成10进制的数字
    并且new Integer返回回去,而第一句话中的intValue其实还没有调用就已经出现异常了.在第二句话中,
     public static int parseInt(String s) throws NumberFormatException {
    return parseInt(s,10);
        }
    是直接返回了parseInt的结果,返回的是一个int.
    在看原代码的时候,发现错误出现在下边的parseInt函数中public static int parseInt(String s, int radix)
    throws NumberFormatException
        {
            if (s == null) {
                throw new NumberFormatException("null");
            } if (radix < Character.MIN_RADIX) {
        throw new NumberFormatException("radix " + radix +
        " less than Character.MIN_RADIX");
    } if (radix > Character.MAX_RADIX) {
        throw new NumberFormatException("radix " + radix +
        " greater than Character.MAX_RADIX");
    } int result = 0;
    boolean negative = false;
    int i = 0, max = s.length();
    int limit;
    int multmin;
    int digit; if (max > 0) {
        if (s.charAt(0) == '-') {
    negative = true;
    limit = Integer.MIN_VALUE;
    i++;
        } else {
    limit = -Integer.MAX_VALUE;
        }
        multmin = limit / radix;
        if (i < max) {
    digit = Character.digit(s.charAt(i++),radix);
    if (digit < 0) {
        throw NumberFormatException.forInputString(s);
    } else {
        result = -digit;
    }

        }
        while (i < max) {
    // Accumulating negatively avoids surprises near MAX_VALUE
    digit = Character.digit(s.charAt(i++),radix);
    if (digit < 0) {
        throw NumberFormatException.forInputString(s);
    }
    if (result < multmin) {
        throw NumberFormatException.forInputString(s);
    }
    result *= radix;
    if (result < limit + digit) {
        throw NumberFormatException.forInputString(s);
    }
    result -= digit;
        }
    } else {
        throw NumberFormatException.forInputString(s);
    }
    if (negative) {
        if (i > 1) {
    return result;
        } else { /* Only got "-" */
    throw NumberFormatException.forInputString(s);
        }
    } else {
        return -result;
    }
        }
    红色的是出错部分...自己看看吧..
      

  3.   

    digit = Character.digit(s.charAt(i++),radix);
            if (digit < 0) {
                throw NumberFormatException.forInputString(s);
            } else {
                result = -digit;
            }

    怎么没标出来,这是出错的部分
      

  4.   

    你用的jdk1.4吧,1.5好像不抛ClassCastException异常,只抛NumberFormatException异常。
    int iInca = Integer.valueOf((String) m.get("INCREMENTVAL")).intValue(); 这个抛ClassCastException异常,是因为valueOf()方法要返回一个Interger,也就是把一个string转换成一个Integer,如果转换出错,就会抛这个异常。
      

  5.   

    我用的1.6也一样是抛出的  throw NumberFormatException.forInputString(s); 
    原代码里写出来的
      

  6.   

    (String) m.get("INCREMENTVAL")返回的是一个什么类型的?