Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method format(String, Object[]) in the type String is not applicable for the arguments (...)

Here is my code:

int hoursFormat = 1, minsFormat = 2, secsFormat = 3;
String timeFormat = String.format("%02d:%02d:%02d",hoursFormat, minsFormat, secsFormat);

This gives a compilation error:

Unresolved compilation problem: 
    The method format(String, Object[]) in the type String is not applicable for the 
      arguments (String, int, int, int)

Why am I getting this error here and how can I fix it?

like image 352
Barnes Noble Avatar asked Oct 09 '11 04:10

Barnes Noble


3 Answers

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?

like image 81
yankeemike Avatar answered Nov 18 '22 19:11

yankeemike


Are you using Java version 1.4 or below? Autoboxing wasn't introduced until Java 5. Try manually boxing ints to Integers.

like image 29
johnidis Avatar answered Nov 18 '22 19:11

johnidis


Are you using eclipse?

If so sometimes, issues like this appear, when everything seems to be correct. Here is how I just solved it:

  • Right click on project and go to properties->Java Compiler
  • You would be seeing a recent Compiler compliance level (1.7 in my case) set in the drop down ("compiler compliance level"). Also same version is seen set below in "Generated .class files compatibility" and "Source compatibility".

Now:

  • Select the Checkbox: "Use default compliance settings"
  • Notice that a lower version (in my case 1.1) got set for: "Generated .class files compatibility" and "Source compatibility". This is the issue, although eclipse is showing that it is compiling using a higher compiler it is not.
  • In the drop down "compiler compliance level" choose some other level and then select the one you want. The changes would be reflected below in "Generated .class files compatibility" and "Source compatibility".

This should have resolved the issue.

like image 1
user1953366 Avatar answered Nov 18 '22 19:11

user1953366