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()));

运行成功了

像这一类的错误都是非常小的点,只能多经历才能避免了


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM