• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with ArrayList  RSS feed

 
Beth Laguardia
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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!
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
I understand now. Thanks for the reply.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!