Here is my code:
int hoursFormat = 1, minsFormat = 2, secsFormat = 3;
String timeFormat = String.format(\"%02d:%02d:%02d\",hoursFormat, minsFormat, secsForma
Are you using Java version 1.4 or below? Autoboxing wasn't introduced until Java 5. Try manually boxing int
s to Integer
s.
You have jdk 1.4
or below version. The method String.format() is introduce in Jdk 1.5
.
Take a look at coderanch post.
I had a similar problem with printf. I am using JDK 1.6.0_27. Setting the compliance level to 1.6 solved my issue. This can be set in the following way.
Project > Properties > Java Compiler
You can also refer to the following thread:
Why am I getting a compilation errors with a simple printf?
I'm gonna vote for a clean build. There's no reason it should be failing like this, especially when you try manually boxing to Integer. Are you using Eclipse? Sometimes it gets confused, and you just have to rebuild everything.
Are you using eclipse?
If so sometimes, issues like this appear, when everything seems to be correct. Here is how I just solved it:
Now:
This should have resolved the issue.
The signature of format is:
public static String format(String format, Object ... args) {
return new Formatter().format(format, args).toString();
}
and it seems no any mistakes in your code, for my suggestion try to run this with console application without using any IDE (For test purpose).