java.util.MissingFormatArgumentException: Format specifier ‘%s‘ 生成异常信息 已解决

java.util.MissingFormatArgumentException: Format specifier '%s'
	at java.util.Formatter.format(Formatter.java:2519) ~[?:1.8.0_131]
	at java.util.Formatter.format(Formatter.java:2455) ~[?:1.8.0_131]
	at java.lang.String.format(String.java:2940) ~[?:1.8.0_131]
	
根据这个异常,你根本找不到异常的具体位置,  所以我们将异常信息进行打印
   // 生成异常信息   
    public static  String convException(Exception e){
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        StringBuffer buffer = sw.getBuffer();
        return  buffer.toString();
    }


在这里插入图片描述
在这里插入图片描述
报错: 下标索引越界 index: 519 文件内 : 518

解决: 将txt文本内容 UTF-8 改成 ANSI 格式

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
从 Windows 3.0 SDK 发掘的资源,英文原版 + HTML版本 Microsoft Codeview and Utilities User's Guide Microsoft(R) CodeView(R) and Utilities User's Guide Version 2.3 for MS(R) OS/2 and MS-DOS(R) Operating Systems MICROSOFT CORPORATION Information in this document is subject to change without notice and does not represent a commitment on the part of Microsoft Corporation. The software described in this document is furnished under a license agreement or nondisclosure agreement. The software may be used or copied only in accordance with the terms of the agreement. It is against the law to copy the software on any medium except as specifically allowed in the license or nondisclosure agreement. No part of this manual may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying and recording, for any purpose without the express written permission of Microsoft. (c)Copyright Microsoft Corporation, 1987, 1989. All rights reserved. Simultaneously published in the U.S. and Canada. Printed and bound in the United States of America. Microsoft, MS, MS-DOS, XENIX, and CodeView are registered trademarks of Microsoft Corporation. AT&T is a registered trademark of American Telephone and Telegraph Company. Eagle is a registered trademark of Eagle Computer, Inc. IBM is a registered trademark of International Business Machines Corporation. Intel is a registered trademark of Intel Corporation. Lotus is a registered trademark of Lotus Development Corporation. Tandy is a registered trademark of Tandy Corporation. Document No. LN0801A-500-R00-0889 Part No. 07824 10 9 8 7 6 5 4 3 2 1 %@CR:MCVTOC00@% Table of Contents Introduction New Features of the CodeView(R) Debugger About this Manual Document Conventions Part 1 The CodeView Debugger Chapter 1 Getting Started 1.1 Restrictions 1.2 The CodeView Environment 1.3 Preparing Programs for the CodeView Debugger 1.3.1 Programming Considerations 1.3.2 CodeView Compile Options 1.3.3 CodeView Link
### 回答1: 这是一个Java异常,意思是缺少格式化参数。具体来说,是在使用字符串格式化时,格式化字符串中使用了%s占位符,但是实际参数中缺少了对应的字符串参数。需要检查代码中的字符串格式化语句,确保所有占位符都有对应的参数。 ### 回答2: 这是Java中的一种运行时异常。它通常表示程序在格式化一个字符串时缺少了必要的参数。在Java中,字符串以%开头,紧跟着一个字符来表示要格式化的数据类型,例如%d表示整数,%s表示字符串。 如果一个格式字符串中包含了一个%字符但没有形式参数(例如一个整数或字符串)来填充它,那么Java运行时系统将会抛出此异常解决此问题的方法是检查代码中的格式化字符串,确保所有的%字符都有正确的形式参数来填充。 如果一个字符串中包含了多个%字符,那么它们必须与相应的形式参数的数量和类型匹配。如果代码中的格式化字符串没有错误,那么可能是由于输入的参数类型与格式化字符串中的类型不匹配而导致的。在这种情况下,需要检查输入的参数类型并确保它们与格式化字符串中的类型匹配。 如果以上方法都不能解决问题,那么可以通过打印格式化字符串和形式参数的值来debug。通过查看日志输出,可以确定哪个参数在格式化字符串中缺失,从而进一步诊断和修复问题。 总之,java.util.missingformatargumentexception: format specifier '%s'异常通常是由于代码中的格式化字符串和形式参数不匹配或缺失所引起的。通过检查代码并打印输出日志,可以找到并解决这个问题。 ### 回答3: java.util.missingformatargumentexception: format specifier '%s' 是Java中一种常见的异常。在程序中,当使用格式化字符串时,应该保证格式字符串与实参的数量和类型匹配,否则会抛该异常。 在具体的实现中,当使用格式化字符串时,可以使用类似于"%d"、"%f"、"%s"等格式描述符来指示格式化的变量类型。同时,使用格式化字符串时应该按照所需的参数数量依次提供参数,这些参数的类型应该与对应的格式描述符匹配。 当程序中存在格式字符串与实参数量或类型不匹配的情况时,就会抛出java.util.missingformatargumentexception: format specifier '%s'异常。可以通过检查异常信息来确定出问题的格式字符串以及实参的数量和类型,然后进一步修改代码以解决异常。 需要注意的是,在使用格式化字符串时,应该尽可能地使用官方提供的格式描述符,并根据具体业务需求灵活调整。同时,应该对输入的数据进行检查,确保其类型以及内容符合要求,以避免引发异常

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值