Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
610 views
in Technique[技术] by (71.8m points)

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

Why do I get the following compilation error with a simple call to printf? My code:

import java.util.Scanner;

public class TestCodeBankAccInputs
{
    public static void main(String[] args)
    {
        String displayName = "Bank of America Checking";
        int balance = 100;
        System.out.printf("%s has %7.2f", displayName, balance);
    }
}

On compilation I get the following error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
  The method printf(String, Object[]) in the type PrintStream is not applicable for the 
    arguments (String, String, double)
  at TestCodeBankAccInputs.main(TestCodeBankAccInputs.java:9)

What's causing this and how can I fix it?

Version information:

Help->About in Eclipse gives following information:

Eclipse Java EE IDE for Web Developers.

Version: Indigo Release Build id: 20110615-0604

The JDK I installed is JDK1.6.0_27

I have seen this similar issue regarding String.format. Some users have suggested it might be a build issue, but looks like I have updated versions.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Project > Properties > Java Compiler

if Enable project specific settings is not set, use the Configue Workspace Settings... link on that page to check the global Compiler compliance level.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...