1. 程式人生 > 實用技巧 >java.lang.NumberFormatException: For input string: "method:{0}.{1}"處理

java.lang.NumberFormatException: For input string: "method:{0}.{1}"處理

寫測試時用佔位符 MessageFormat.format 輸出報錯

仔細查看了一下我的語句

 System.out.println(MessageFormat.format(
                "{method:{0}.{1},params:{2},user:[id:{3},username:{4}],ip:{5},dateTime:{6},operationCode:{7},type:{8},creater:{9},requestUrl:{10}}"
                ,cla,method,json.toString(),userid,username,ip,new Date().getTime(),"ceshi",request.getMethod(),"ceshiCreater",request.getRequestURL()));

發現format不允許{..{0}...}這樣的形式,然後我改成了...{0}...

System.out.println(MessageFormat.format(
                "method:{0}.{1},params:{2},user:[id:{3},username:{4}],ip:{5},dateTime:{6},operationCode:{7},type:{8},creater:{9},requestUrl:{10}"
                ,cla,method,json.toString(),userid,username,ip,new Date().getTime(),"ceshi",request.getMethod(),"ceshiCreater",request.getRequestURL()));

執行成功了

像這一類的錯誤都是非常小的點,只能多經歷才能避免了