0

For some reason, in Eclipse, I get the error "change type of 'i' to 'Object[]'" for the "format" here:

int i = 461012;
System.out.format("The value of i is: %d%n", i);

I experience this error with JDK 7 and 8 (I tried reinstalling both in turn, and I tried the latest eclipse download, just to be safe).

I'm very confused as to why I can't use an int here. This example comes directly from the Oracle documentation for format. printf gives the same error.

Something so simple should be robust and reliable, one would think.

ON EDIT:

Sorry, here's the entire code that doesn't work for me.

public class Main {

    public static void main(String[] args) {
        int i = 461012;
        System.out.format("The value of i is: %d%n", i);

    }

}

And here's exactly what I see in Eclipse when I hover over "format" with the mouse:

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

1 quick fix available:

Change type of 'i' to 'Object[]'.

Does that help?

1 Answers1

1

The only reason I can think of is that the you Java compliance level set to 1.4. I think it is very probable that this is causing the observed error. Printf didn't exist in Java 1.4

Check that the Compiler compliance level is set to at least 1.5 for your project.

This answer shows how to change compliance level in Eclipse

Community
  • 1
  • 1
coder hacker
  • 4,819
  • 1
  • 25
  • 50