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

程序:

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. django认证01---token

    1.登录鉴权跟 Token 的鉴权区别 以 Django 的账号密码登录为例来说明传统的验证鉴权方式是怎么工作的,当我们登录页面输入账号密码提交表单后,会发送请求给服务器,服务器对发送过来的账号密码进 ...

  2. PAT甲级 散列题_C++题解

    散列 PAT (Advanced Level) Practice 散列题 目录 <算法笔记> 重点摘要 1002 A+B for Polynomials (25) 1009 Product ...

  3. Python连接ORACLE操作

    一.准备工作 1.安装cx_Oracle ttps://pypi.python.org/pypi下查找cx_Oracle并下载 执行安装命令 pip install cx_Oracle-6.0rc1- ...

  4. Linux虚拟机常用命令

    参考原文链接:(https://blog.csdn.net/fanyun_01/article/details/51083585) 一.Linux虚拟机常用命令 # virsh list //查看已打 ...

  5. go hello world第一个程序

    main 函数所在的包名必须使用main import "fmt"  导入包fmt  fmt包包含了Println方法的定义 func main() 程序运行入口方法和c语言相似 ...

  6. 2019牛客多校一 H. XOR (线性基)

    大意: 给定序列, 求所有异或和为$0$的子序列大小之和. 先求出线性基, 假设大小为$r$. 对于一个数$x$, 假设它不在线性基内, 那么贡献为$2^{n-r-1}$ 因为它与其余不在线性基内数的 ...

  7. Myatis之bind标签

    myBatis的bind的标签,一般的用法都是 <if test="name!= null and name!= '' "> <bind name="u ...

  8. asp.net core 2.0发布到IIS报错解决方案

    大体来说,是环境的问题. 第一个错误,如图: 1. 查了网上说是文件夹权限的问题,依次设置了Everyone权限和IIS_IUSER权限,能勾选的都勾选了,然而并没有什么用,看来不是这个问题导致的. ...

  9. ThinkPad T420i 上 Ubuntu 12.04 实现指纹识别登录

    ThinkPad T420i 上 Ubuntu 12.04 实现指纹识别登录 # add ppa add-apt-repository ppa:fingerprint/fprint # update ...

  10. ADF一个EO的事物提交周期

    客户端通过传递键对象调用实体定义的findByPrimaryKey(),获得EO.ADF框架首先检查实体缓存, 如果在实体缓存中没有找到实体,就执行SQL SELECT查询,从数据库读取行.示例如下: ...