new Long((String)ci.getPm("cardLength")
如果我的cardLength的值为空,咋办?

解决方案 »

  1.   

    出异常呗....所以建议分开来写, 加上是否为null的判断.
      

  2.   


     
    long id;

    try{
    id = Long.parseLong((String)ci.getPm("cardLength"));
    }catch(NumberFormatException e){
    id = 0;
    }
      

  3.   

    我知道了
        if(!cardAI.equals("")){
             sysCustCardRule.setCardAffixIndex(new Long((String)ci.getPm    ("cardAffixIndex")));
              }
    else{
           //sysCustCardRule.setCardAffixIndex(new Long(""));
    }
      

  4.   

    sysCustCardRule.setCardAffixIndex("".equals(ci.getPm("cardAffixIndex"))?"":new Long(ci.getPm("cardAffixIndex"))); 
      

  5.   

    ""是String类型,new Long()是Long类型,要出错的。
      

  6.   

    String s = (String)ci.getPm("cardLength");
    Long l = new Long((s==null || "".equels(s))?"0":s);
    s里有非数字时会报NumberFormatException
      

  7.   

    new Long((String)(ci.getPm("cardLength") == null || "".equal(ci.getPm("cardLength"))
    ? "0":ci.getPm("cardLength") ))