Archive for the ‘Programming’ Category

Java Error: Exception in thread „main“ java.util.IllegalFormatConversionException:

Montag, April 6th, 2009

I wonder, why I get follow error, when I compiled my little test java programm:

Exception in thread „main“ 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 klassen.Konsole.main(Konsole.java:11)

My mistake is in this line:

System.out.print(String.format(„%f „, i));

I choose the false letter. „%f“ must chosen if I have a double variable. But my variable i is Integer, so the right solution is

System.out.print(String.format(„%d„, i));

Little mistake, big effect.