• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

ArrayList:

 
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
 
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
 
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.
 
Ranch Hand
Posts: 71
Hibernate Spring Java
  • 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: 71
Hibernate Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you try this syntax:
ArrayList<Integer> al=new ArrayList<Integer>();
 
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.).
 
Marshal
Posts: 65814
250
  • 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
Marshal
Posts: 65814
250
  • 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.
 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!