Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

arraylist problem

 
sam jones
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello there im just starting java and really programming in general, but i am going through the head first java book, and i am having trouble with one of the exercises, i have spent at least an hour typing and retyping this code and checking it against the book, but i cannot find whats causing the error, this is the exact code i am using(below) and it return this error every time i try and compile it:



any advice on how to fix this would be much appreciated, thank you

Edit: Sorry, did not think about the copyright issue (code deleted)
[ August 09, 2008: Message edited by: sam ]
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a method with a signature of:

And you use this code to call it:


Like the error says, you can't call a method that expects an ArrayList of Strings and pass it an array of ints.

So what does the book have to say about this code? What do you think you can do to resolve this?
 
Alex Barfoot
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here you are trying to call the setLocationCells method giving an int array as the needed parameter when the method setLocationCells only takes ArrayList<String>

I have the book ill go look at the code and see what you done wrong.

Edit found the problem:
The first class you have there is for the first simple dot com game the book does before you learn about Arraylists the second class comes from the full game which the book does after that. You are simple mixing the classes up.
Also the code in the book is copyright protected so you are not supposed to post it on the forum.


[ August 09, 2008: Message edited by: alex barfoot ]
[ August 09, 2008: Message edited by: alex barfoot ]
 
Katrina Owen
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi redbeard,

Please check your private messages for an important administrative message from the staff.

Thanks,
Katrina
JavaRanch Saloon Bartender
 
sam jones
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
alright sorry about that just did not think they would give that code and not tell you need to edit more code to make it work, i did think about the fact that we had an int array trying to be fed into a String arraylist, i just assumed you could read an array into an arraylist of the same type so i tried changing the arraylist to type int, and that's as far as i got, thanks a lot for the help though
[ August 09, 2008: Message edited by: sam ]
 
Katrina Owen
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, Sam,

Would you please take the time to read the JavaRanch Naming Policy and change your display name to match?

Thanks,
Katrina
Saloon Bartender
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic