| Author |
ArrayList:
|
zama syed
Greenhorn
Joined: Sep 28, 2010
Posts: 6
|
|
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
Joined: Mar 17, 2010
Posts: 1046
|
|
|
Welcome to javaRanch please use codetags while posting your queries
|
SCJP6.0,My blog Ranchers from Delhi
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1046
|
|
|
But it works for me
|
 |
Ed Ward
Ranch Hand
Joined: Jan 30, 2006
Posts: 147
|
|
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
Joined: Sep 08, 2010
Posts: 64
|
|
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).
|
dkj4jdk
|
 |
zama syed
Greenhorn
Joined: Sep 28, 2010
Posts: 6
|
|
|
The version i am using is 6.0
|
 |
Deepak Kumar Jena
Ranch Hand
Joined: Sep 08, 2010
Posts: 64
|
|
Why don't you try this syntax:
ArrayList<Integer> al=new ArrayList<Integer>();
|
 |
Soumyajit Hazra
Ranch Hand
Joined: Jun 26, 2007
Posts: 136
|
|
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.).
|
Java Programmer | SCJP 1.5 | SCWCD 1.4
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32689
|
|
|
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
Joined: Sep 28, 2010
Posts: 6
|
|
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
Joined: Oct 13, 2005
Posts: 32689
|
|
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.
|
 |
 |
|
|
subject: ArrayList:
|
|
|