Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList:

 
zama syed
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

on executing below program 'm getting some errors:


Error:
ArrayListEx1.java:7: cannot resolve symbol
symbol : method add (int)
location: class java.util.ArrayList
al.add(10);
^
ArrayListEx1.java:8: cannot resolve symbol
symbol : method add (int)
location: class java.util.ArrayList
al.add(20);
^
ArrayListEx1.java:9: cannot resolve symbol
symbol : method add (int)
location: class java.util.ArrayList
al.add(30);
^
3 errors
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to javaRanch please use codetags while posting your queries
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But it works for me
 
Ed Ward
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of Java?
I don't think the auto-boxing feature came about until 1.5.
Under 1.4, you will gt a compile time error for the source you provided.
 
Deepak Kumar Jena
Ranch Hand
Posts: 68
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jama, Welcome to Javaranch As Ed Ward has mentioned it depends on the version of Java you are using. If you are using Java 5.0 or above it willl compile, run and give output as in Java 5.0 (or above) as Autoboxing/Unboxing feature is available in it. But if you are using previous versions of Java it supports only Colloections of Objects. As you are trying to store int values which are primitives, you need the corresponding wrapper class (Integer in this case) while inserting to treat it as Object type or you need explicit type casting in the time of retrieving . Hope you got it ..
One more request to you, do not use short texts and make the whole text bold rather the important points and while posting use corresponding threads (in this case Beginning Java or Java in General).
 
zama syed
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The version i am using is 6.0
 
Deepak Kumar Jena
Ranch Hand
Posts: 68
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you try this syntax:
ArrayList<Integer> al=new ArrayList<Integer>();
 
Soumyajit Hazra
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the PATH variable whether it points to some older version of java. For you example the PATH should hold value something like
PATH=<Java6 Home>/bin;%PATH% (windows env.).
 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is quicker to write javac -version and java -version at a command line, and see whether you get the same for both.
 
zama syed
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Documents and Settings\Administrator>java -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing)


 
Campbell Ritchie
Sheriff
Pie
Posts: 48972
60
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you wrote javac -version?

Welcome to the Ranch Sorry we didn't notice you are new. Please use the code button for code; I have edited your code and you can see how much better it looks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic