[Java]format string is malformed java
format string is malformed java
最近在做代码审查,发现很多在使用 String.format 的时候遇到了IDEA报的 Format string 'xxx' is malformed 警告。
顾名思义,错误是标识字符串格式不正确,也就是说由于使用了格式不正确的字符串格式化指令导致的。
这次发现的错误的使用如下:
String.format("提交失败!s% 不存在!", name)
很明显是 s% 标识的使用错误,导致IDEA报出了Format string 'xxx' is malformed 警告。
正确的写法应该是:
String.format("提交失败!%s 不存在!", name)
虽然是一个不经意的小错误,但有可能会造成大问题。还是要细心。
提供一下 String.format 不同转换符实现不同数据类型到字符串的转换表格:

一些转换符标志:

[Java]format string is malformed java的更多相关文章
- Java EE之Struts2异常[No mapping found for dependency [type=java.lang.String, name='actionPackages'#java.lang.RuntimeException]【摘抄】
本博文摘自:http://www.blogjava.net/nkjava/archive/2009/03/29/262705.html 出现这个问题,可能是添加了struts2-codebehind包 ...
- 【spring boot】spring boot 前台GET请求,传递时间类型的字符串,后台无法解析,报错:Failed to convert from type [java.lang.String] to type [java.util.Date]
spring boot 前台GET请求,传递时间类型的字符串,后台无法解析,报错:Failed to convert from type [java.lang.String] to type [jav ...
- org.hibernate.TypeMismatchException: Provided id of the wrong type for class cn.itcast.entity.User. Expected: class java.lang.String, got class java.lang.Integer at org.hibernate.event.internal.Defau
出现org.hibernate.TypeMismatchException: Provided id of the wrong type for class cn.itcast.entity.User ...
- No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, org.springframework.boot.logging.LogLevel>]
java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.conte ...
- No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.lang.String, java.lang.String>]
java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.conte ...
- Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2020-02-06'; nested exception is java.lang.IllegalArgumentException]解决
今天做springbook项目前端输入日期传到数据库保存报了一下错误 Whitelabel Error Page This application has no explicit mapping fo ...
- setLocale(java.util.Locale), setCharacterEncoding(java.lang.String),setContentType(java.lang.String type)
对于setCharacterEncoding(java.lang.String),这个方法是javax.servlet.ServletRequest和javax.servlet.ServletResp ...
- java.lang.String 类源码解读
String类定义实现了java.io.Serializable, Comparable<String>, CharSequence 三个接口:并且为final修饰. public fin ...
- Java 异常 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date'
查询时发送给服务器的日期的字符串格式:yyyy-MM-dd HH:mm:ss 服务器接收到日期的字符串之后,向 MySQL 数据库发起查询时,因为没有指定日期时间格式,导致字符串数据不能正确地转换为日 ...
- java中String的常用方法
java中String的常用方法1.length() 字符串的长度 例:char chars[]={'a','b'.'c'}; String s=new String(chars); int len= ...
随机推荐
- 2023全国大学生电子设计竞赛H题全解 [原创www.cnblogs.com/helesheng]
2023年又是全国大学生电子设计竞赛年,一如既往的指导学生死磕H题.8月2日看到公布的赛题,我自己还沾沾自喜,觉得今年学生用嵌入式系统和数字信号处理知识就可以完成这题,赛前都辅导过,应该成绩不差.哪想 ...
- Pgsql之查询一段时间内的所有日期
前几天干活儿的时候,项目中有这么个需求,需要用pgsql查询两个日期间的所有日期,包括年月日,下面贴代码: 1 select date(t) as day 2 from 3 generate_seri ...
- CSS - 工具类 tool.css
/* flex */ .flex{ display: flex; } .f1{ flex:1 } .flex-center{ align-items: center; ...
- apicloud(沉浸式导航篇) - 手机状态栏 有黑边的解决办法
在 index.html 的 apiready 中加上 第一种 : 可设置全屏 api.setFullScreen({ fullScreen: true }); 第二种:设置状 ...
- CAP-BASE
- [转帖][java] GC (Allocation Failure)日志分析
日前查看某个程序的日志,发现一直在报GC相关的信息,不确定这样的信息是代表正确还是不正确,所以正好借此机会再复习下GC相关的内容: 以其中一行为例来解读下日志信息: [GC (Allocation F ...
- [转帖]ssh_exporter
https://github.com/treydock/ssh_exporter SSH exporter The SSH exporter attempts to make an SSH conne ...
- [转帖]银河麒麟高级服务器操作系统V10SP1安装Docker管理工具(Portainer+DockerUI)
文章目录 一.系统环境配置 二.安装Docker 三.安装Docker管理工具 Docker管理工具之Portainer Portainer简介 Portainer安装 Portainer访问测试 D ...
- github-keydb 知识
https://github.com/Snapchat/KeyDB KeyDB is now a part of Snap Inc! Check out the announcement here R ...
- 【贪心】AGC018C Coins
Problem Link 现在有 \(X+Y+Z\) 个人,第 \(i\) 个人有三个权值 \(a_i,b_i,c_i\),现在要求依次选出 \(X\) 个人,\(Y\) 个人和 \(Z\) 个人(一 ...