我目前正在从网络中获取数据,并打印出来在一个JTextArea代码。 在这两者之间,我想基于定线的小数点位置数。 这是实现小数点对齐之前工作的代码:
private static final String NewLine = System.getProperty("line.separator");
String NetString = "";
byte[] data = p.getData();
NewString += "SID: " + BuildShort(data,4) + NewLine;
NewString += "DID: " + BuildShort(data,6) + NewLine;
这是新的
NewString += String.format("%-8s%11.5f" + NewLine, "SID : ", BuildShort(data,4));
NewString += String.format("%-8s%11.5f" + NewLine, "DID : ", BuildShort(data,6));
我接收到该错误消息
Exception in thread "Thread-2" java.util.IllegalFormatConversionException: f != java.lang.Integer
at java.util.Formatter$FormatSpecifier.failConversion(Unknown Source)
at java.util.Formatter$FormatSpecifier.printFloat(Unknown Source)
at java.util.Formatter$FormatSpecifier.print(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.lang.String.format(Unknown Source)
at MT302.ParsePacket(MT302.java:97)
at MK20_DataView.run(MK20_DataView.java:261)
at java.lang.Thread.run(Unknown Source)
你知道为什么我收到这个错误?