错误是在ArrayList中的list.add未来() [英] Error is coming in Arraylist 's list.add()

查看:1108
本文介绍了错误是在ArrayList中的list.add未来()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Eclipse朱诺,我有ArrayList的家伙讨好help.here的。新增()麻烦的是我的code

I am using Eclipse JUno ,I am having trouble with the .add() of the arraylist guys please help.here is my code

     import java.util.ArrayList;
public class A
{
public static void main(String[] args) 
  {
    ArrayList list=new ArrayList();
    list.add(90);
    list.add(9.9);
    list.add("abc");
    list.add(true);
    System.out.println(list);
  }
}

这是今后的错误是:

the error which is coming is :

 Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    The method add(int, Object) in the type ArrayList is not applicable for the arguments (int)
    The method add(Object) in the type ArrayList is not applicable for the arguments (double)
    The method add(Object) in the type ArrayList is not applicable for the arguments (boolean)

    at A.main(A.java:7)

但这里是奇怪的事情,该行

but here is the weird thing ,that the line

  list.add("abc");

不会导致任何错误。增加列表的方法需要一个参数,它是那么为什么我面临这个问题的对象类型,请帮助guys..i已经搜查了很多,我没有得到任何solution.I要做就这个问题和由于这种错误的做法我不能继续我的做法。

is not causing any error.. ADD method of list take one argument which is an object type then why i am facing this problem please help guys..i had searched a lot i did not get any solution.I have to do practice on this and due to this error i cant continue my practice..

推荐答案

我想你使用的是Java先前的版本1.5。 自动装箱在Java 1.5中引入的。和你的code编译java的1.5 +罚款。

I suppose that you're using java prior version 1.5. Autoboxing was introduced in java 1.5. And your code compiles fine on java 1.5+.

编译源1.4:

javac -source 1.4 A.java


A.java:7: error: no suitable method found for add(int)
    list.add(90);
        ^
    method ArrayList.add(int,Object) is not applicable
      (actual and formal argument lists differ in length)
    method ArrayList.add(Object) is not applicable
      (actual argument int cannot be converted to Object by method invocation conversion)
A.java:8: error: no suitable method found for add(double)
    list.add(9.9);
        ^
    method ArrayList.add(int,Object) is not applicable
      (actual and formal argument lists differ in length)
    method ArrayList.add(Object) is not applicable
      (actual argument double cannot be converted to Object by method invocation conversion)
A.java:10: error: no suitable method found for add(boolean)
    list.add(true);
        ^
    method ArrayList.add(int,Object) is not applicable
      (actual and formal argument lists differ in length)
    method ArrayList.add(Object) is not applicable
      (actual argument boolean cannot be converted to Object by method invocation conversion)
3 errors

1.5(或更高版本):

With 1.5 (or later):

javac -source 1.5 A.java

warning: [options] bootstrap class path not set in conjunction with -source 1.5
Note: A.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 warning

我建议你手动更新你的java 或框中的所有原语对象,@SoulDZIN建议。

I suggest you to update your java or box all primitives to objects manually, as @SoulDZIN suggested.

这篇关于错误是在ArrayList中的list.add未来()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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