2

I'm trying to compile code that I know to be working on other peoples' machines but is throwing a particular error on my system. Specifically the error relates to the printf() method

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

For instance

public static void main(String[] args) {

        double rate =10.5;
        System.out.printf("%.3f",  rate);
    }

Does anyone know why this error is cropping up? There are alternatives to using printf(), but this is very annoying!

3
  • Try wrapping it in new Object[] {rate}. Commented Oct 20, 2013 at 20:23
  • I don't get the same error with that code. I suspect that something else is wrong. Commented Oct 20, 2013 at 20:36
  • What Java version are you using? Commented Oct 20, 2013 at 20:45

2 Answers 2

4

Is it possible that you hav Java compiler compliance level 1.4?

Sign up to request clarification or add additional context in comments.

6 Comments

Is this an answer to OP's problem, or rather a comment? I guess it's probably the second.
I should rephrase that: The only explanation I can think of is that the OP has its Java compliance level set to 1.4. I think it is very probable that this is causing the observed error.
@EelLee: I think that this answer is closer to the mark than yours. 1+ up-vote. I don't see anywhere in the code example or the error message where autoboxing applies. I do see however where printf didn't exist in Java 1.4.
@HovercraftFullOfEels I don't think this meets any standard of answering (as I'm reading different questions, I notice that experienced users put such a questions in the comments), yet I think it's worth to ask the author which Java version he's using (which I have just did). Thanks.
To make clear: the question is not which Java version you are using, but which Java Compiler compliance Level, see e.g. the Eclipse documentation on this setting: help.eclipse.org/juno/…
|
0

The funny thing is that it compiles without problem on Java 7, and prints out

10.500

It probably uses autoboxing. But omitting the issue of autoboxing - as your method accepts only Objects, and not primitives, you need to use a wrapper Double.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.