今天,我弟遇到一个有意思的错误~

程序:

package com.mq.ceshi1;

public class StringFormat {
  public static void main(String[] args) {
    int num = 10;
    int num2 = 5;
    System.out.println(String.format("%d / %d = %d", num,num2,num / num2));
  }
}

报了The method format(String, Object[]) in the type String is not applicable for the arguments (String, int,int,int)错误。

首先分析一下,jdk文档:

可见,这个是在1.5版本后添加的。

后来,根据网上的修改,按以下运行也是正常的。

package com.mq.ceshi1;

public class StringFormat {
  public static void main(String[] args) {
    // int num = 10;
    // int num2 = 5;
    Integer [] nums = {10,5,2};
    // System.out.println(String.format("%d / %d = %d", num,num2,num / num2));
    System.out.println(String.format("%d / %d = %d", nums));
  }
}

查看了出问题机器使用的是:jdk版本也是1.7.8  myecliplse8.6

由于版本大于1.5,但是我还是怀疑是版本引起的。于是,在有问题的机器上,由使用了1.5版本之后才有的自动拆装箱机制。

Integer num = 5;  //发现报错

进一步验证了我关于版本可能带来的错误。

于是,将myecliplse版本升级到2014版,发现问题消失。

总结:怀疑是myeclipse8.6版本与jdk1.7.8存在不兼容的问题。(暂无直接证据,如果哪位有方法验证的话,请不吝赐教!!)

The method format(String, Object[]) in the type String is not applicable for the arguments的更多相关文章

  1. The method setClass(Context, Class<?>) in the type Intent is not applicable for the arguments (GameV

    在当前短信内容的activity中写            Bundle bun = new Bundle();         bun.putString("message",  ...

  2. 错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyFragment)

    Fragment newfragment =new MyFragment();fragmentTransaction.replace(R.layout.activity_main,newfragmen ...

  3. The method load(Class, Serializable) in the type HibernateTemplate is not applicable for the arguments (Class, int)

    引入别人的项目发现利用HibernateTemplate的load的方法报错了.错误提示为: The method load(Class, Serializable) in the type Hibe ...

  4. The method setOnClickListener(View.OnClickListener) in the type View is not applicable

    开始学习 android 了,学习的是高明鑫老师的android视频教程(android视频教学). 学到第八讲时, 在写动态设置时报错: The method setOnClickListener( ...

  5. The method setItems(String) in the type ForTokensTag is not applicable for the arguments (Object)

    1. 问题 看到这个错误以为是貌似jsp页面有误,c:forTokens标签用错了?? An error occurred at line: in the jsp file: /WEB-INF/pag ...

  6. The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, SettingFragment, String)

    The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the ...

  7. The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new View.OnClickListener(){}, String, int)

    package comxunfang.button; import android.support.v7.app.ActionBarActivity; import android.os.Bundle ...

  8. 自己写的demo。List<HashMap<String,Object>>=new ArrayList<HashMap<String,Object>>

    package com.pb.collection; import java.util.ArrayList; import java.util.HashMap; import java.util.It ...

  9. 把List<Map<String,Object>>转成Map<String,Object>

    Map<String, Object> parmMap = new HashMap<String, Object>(); //定义一个用于存储强转后的Map List<M ...

随机推荐

  1. Spring Bean装配详解(五)

    装配 Bean 的概述 前面已经介绍了 Spring IoC 的理念和设计,这一篇文章将介绍的是如何将自己开发的 Bean 装配到 Spring IoC 容器中. 大部分场景下,我们都会使用 Appl ...

  2. 详解Cookie、Session和缓存

    1 Cookie和Session Cookie和Session都为了用来保存状态信息,都是保存客户端状态的机制,它们都是为了解决HTTP无状态的问题而所做的努力. Session可以用Cookie来实 ...

  3. Django路由配置

    Django路由配置系统.视图函数 1.路由配置系统(URLconf) URL配置(URLconf)就像Django 所支撑网站的目录.它的本质是URL与要为该URL调用的视图函数之间的映射表:你就是 ...

  4. 20-MySQL DBA笔记-可扩展的架构

    第20章 可扩展的架构 本章将为读者讲述可扩展的架构相关的知识和技术.可扩展的架构意味着这个架构伸缩性好,我们可以用更多的节点来提高吞吐率,而性能(响应时间)不会下降到不可接受的范围.互联网世界飞速发 ...

  5. (十三)JSON的使用(下)

    (接上一章节) 4.2 使用ajax交互方式 使用ajax的转换思想        A:异步请求在页面中发起,也要在页面中接收数据并展现. B:ajax中的数据不能从作用域中获取,只能从respons ...

  6. (十五)SpringBoot之使用Redis做缓存数据

    一.添加Redis依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns=" ...

  7. SQL优化中的重要概念:阻塞

    原文:SQL优化中的重要概念:阻塞 上一篇讲到锁定的概念,那么接下来就是如何找到由于锁定而发生阻塞的进程,并解决阻塞问题. 1.会话1,修改数据,但没有提交事务 BEGIN TRAN select @ ...

  8. Linux装好系统之后配置环境

    1.配置IP地址vi /etc/sysconfig/network-scripts/ifcfg-eth0 ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static D ...

  9. Asp.Net Core Linux环境下 找不到配置文件、静态文件的问题

    直接发布会找不到配置文件,和静态文件.需要先cd到项目文件夹,然后在发布.

  10. POJ1484(Blowing Fuses)--简单模拟

    题目链接:http://poj.org/problem?id=1484 这题直接简单模拟即可.给你n个容器,m个操作,最大容量C.模拟每一个对器件的开关操作.如果原来是关闭的,则打开,同时最大功耗加上 ...