1.type是否为空(type != null),每步都需判断(Integer type),否则 type.intValue() 会报空指针错误
if(type != null && type.intValue() == 1){
typeName = "1";}else if( type != null && 2 == type.intValue()){
typeName = "2";
}else if( type != null && 4 == type.intValue()){
typeName = "3";
}
2.Integer type,调用type.intValue()时,确保type不是空,否则报空指针错误
3.Integer.parseInt(value) ,value应该确保非空,否则报空指针错误
4.不得不循环中创建对象时,用完后记得将对象所占内存释放掉
例子:
CdcDistriDetail detail = null;
List<CdcDistriDetail> promoDistriList = new ArrayList<CdcDistriDetail>();
for(int i=1;i<=tgtLength;i++){
detail = new CdcDistriDetail();
detail.setOutRation(outRation);
detail.setWid(wid);
detail.setSrcId(srcId);
detail.setTgtId(Integer.valueOf(tgtIdsArray[i-1]));
detail.setInRation(Double.valueOf(inRationArray[i-1]));
promoDistriList.add(detail );//使用完毕
detail = null;
}
5.Long.valueOf()等中参数不是数字类型的String或者为空,会报错
如:调用:String s = "st"; Long.valueOf(s);
6. DateUtils.parse(,);第一个参数为空,或者不是符合条件的,会报错
调用:
String date ;
DateUtils.parse(date, DateUtils.YMD_OTHER);