String str = "zzz_15922784484_1285462612919_1269306315876" 这是我接口接收到的数据。程序
if (str != null && str.startsWith("zzz_")){
String sub[] = str.split("_");
String strId = sub[2];
long longDecideSmsId = java.lang.Long.parseLong(strId)//为什么这里是乱码呢?
}这是我记录的异常:java.lang.NumberFormatException: For input string: "∞"//为什么数组里的第二个元素成∞了呢。在线等,急。。
if (str != null && str.startsWith("zzz_")){
String sub[] = str.split("_");
String strId = sub[2];
long longDecideSmsId = java.lang.Long.parseLong(strId)//为什么这里是乱码呢?
}这是我记录的异常:java.lang.NumberFormatException: For input string: "∞"//为什么数组里的第二个元素成∞了呢。在线等,急。。
String str = "zzz_15922784484_1285462612919_1269306315876";
if (str != null && str.startsWith("zzz_")) {
String sub[] = str.split("_");
String strId = sub[2];
long longDecideSmsId = java.lang.Long.parseLong(strId);// 为什么这里是乱码呢?
System.out.println(longDecideSmsId);
}
正常…………
LZ DEBUG吧
java.lang.NumberFormatException: For input string: "∞"我不明白的是我接收到的字符串是:zzz_15922784484_1285462612919_1269306315876
程序把第二个元素认为是"∞"了。
这是JDK对这个异常的解释。
当应用程序试图将字符串转换成一种数值类型,但该字符串不能转换为适当格式时,抛出该异常。如果第二个元素存在空格或者其它不合法的信息。哪么也不应该显示出这个啊!"∞"
if (str != null && str.startsWith("zzz_")){
String sub[] = str.split("_");
String strId = sub[2];
//long longDecideSmsId = java.lang.Long.parseLong(strId);//为什么这里是乱码呢?
long longDecideSmsId = new Long(strId);
System.out.println(longDecideSmsId);
}
public Long(String s) throws NumberFormatException {
this.value = parseLong(s, 10);
}
public static long parseLong(String s) throws NumberFormatException {
return parseLong(s, 10);
}没区别
int stloReceivedSms = 0;
int stloSendedSms = 0;
int result = -1;
String content = request.getString("content");//返回内容
String remotePhone = request.getString("remotePhone");
try{
if (content != null && content.startsWith("zzz_")) {
String subCount[] = content.split("_");
String strDecideSmsId = subCount[2].trim();// 批次 //出问题的地方
long longDecideSmsId = java.lang.Long.parseLong(strDecideSmsId);// 通过测试短信返回的内容里得到的短信批次.
log.error("content:" + content + ",strDecideSmsId:"+ strDecideSmsId + ",longDecideSmsId:"+ longDecideSmsId); if (longDecideSmsId > 0) {
String sql = "select a from test1 where b = " + longDecideSmsId;
String sql1 = "select b from test2 where a = " + longDecideSmsId;
stloReceivedSms = this.getStloReceivedSms(db, sql1);//这里的异常在getStloReceivedSms()方法里处理的。不会抛出来
stloSendedSms = this.getStloReceivedSms(db, sql);
int stloReSms = stloReceivedSms + 1;
//这里只是算一个数字,应该不出异常,因为传过去的参数也是合法的。。
double arrival = this.arrival(longDecideSmsId, java.lang.Double.parseDouble("" + stloSendedSms), java.lang.Double.parseDouble("" + stloReSms));
if (stloSendedSms > stloReceivedSms) {
String updateCimSQL = "update test3 set aaa = stloReceivedSms + 1 , bbb = ddd + ' "
+ remotePhone + "' where ccc = ?";
String arrivalSql = "update test4 set aaa = ? where bbb = ?";
try{
int upSTnum = db.executeUpdate(updateCimSQL,new Object[]{longDecideSmsId});
int arrNum = db.executeUpdate(arrivalSql,new Object[]{arrival,longDecideSmsId});
if(upSTnum>0&&arrNum>0){
result = 0;
falg = true;
}
} catch (Exception e) {
result = 0;
CimUtils.errorLog("",
"抵达率执行事务出现异常:" + e.toString(), updateCimSQL
+ "~~~~" + arrivalSql,
"PostRecvSms");
} finally {
}
} else {
result = 0;
}
} else {
result = 0;
}
} else {
result = 0;
}
}catch (Exception e) {
CimUtils.errorLog("", "抵达率出现异常:"+e.toString(), content, "PostRecvSms")//异常是这里出现的。;
}