PrintStream类型中的printf(String,Object [])方法不适用于参数(...) [英] The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (...)

查看:310
本文介绍了PrintStream类型中的printf(String,Object [])方法不适用于参数(...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么通过简单调用printf会出现以下编译错误?我的代码:

  import java.util.Scanner; 

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

编译时出现以下错误:

 线程main中的异常java.lang.Error:未解决的编译问题:
方法printStream类型中的printf(String,Object [])不适用于
参数(String,String,double)
在TestCodeBankAccInputs.main(TestCodeBankAccInputs.java:9)

造成这种情况的原因是什么?如何解决?



版本信息:



帮助 - >关于Eclipse中提供以下信息:



用于Web开发人员的Eclipse Java EE IDE。 / p>

版本:Indigo版本
构建ID:20110615-0604



我安装的JDK是JDK1。 6.0_27



我见过这个类似有关String.format 的问题。一些用户建议它可能是构建问题,但看起来我已经更新了版本。

解决方案

检查<$ c对于您的项目,$ c>编译器合规性级别设置为至少1.5:



项目>属性> Java编译器



如果未启用项目特定设置,请使用配置工作区设置... 在该页面上链接以检查全局编译器合规性级别




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.

解决方案

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.

这篇关于PrintStream类型中的printf(String,Object [])方法不适用于参数(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆