zoukankan      html  css  js  c++  java
  • The method format(String, Object[]) in the type String is not applicable for the arguments

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

    程序:

    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存在不兼容的问题。(暂无直接证据,如果哪位有方法验证的话,请不吝赐教!!)

  • 相关阅读:
    KindEditor编辑器的使用
    导航栏
    ajax php 验证注册用户名是否存在
    PS照片改底色
    截取邮箱@后面内容的两种情况
    js导航栏单击事件背景颜色变换
    model中的自动验证 $_validate $_auto
    一对一关联模型,HAS_ONE
    一对多关联模型,BELONGS_TO
    C++操作MySQL数据库
  • 原文地址:https://www.cnblogs.com/muxi0407/p/6680475.html
Copyright © 2011-2022 走看看