• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with ArrayList

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I purchased the Head First Java And i am into the array list topic already. There's an example named class DotCom where the author used private ArrayList<String> locationCells.

I tried the program but it came up with an error. Please tell me what i generated the ff error: setLocations(java.util.ArrayList<java.lang.Integer> i DotCome cannot be applied to (int [] )
newGame.setLocations(locations);

Here's the code:







I really think that the error is code int [] locations = { randomNum, randomNum + 1, randomNum + 2 }; because it's an integer and the arguments at the array list is a String.

Please help. Thanks!
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int [] locations ... defines locations as an array of int.

public void setLocations(ArrayList<String> loc) ...
the args for setLocations is an object of the ArrayList<String> not an int array.

The compiler doesn't like that and complains.
When you call setLocations you must pass it an arg of the type specified in its declaration, otherwise you'll get a compile error.
 
Beth Laguardia
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I understand now. Thanks for the reply.
reply
    Bookmark Topic Watch Topic
  • New Topic