The above is code from the book Programming Video Games/Evil Genius published in 2008.
The problems are with the .add (line 25) and .get (line 36) for the array called 'games'. I've poked around and it appears that this may have been changed since version 5 which is probably after publication of this book. As you can see, I added "<String>" (line 13 now commented out) when I created the array per examples at Sun website but this had no effect.
Program is supposed to allow user to input elements (strings) to the array and then call them out by their element position. Will not compile or run.
It would help if you'd post the compiler error you get - verbatim. Those errors actually mean something. without you posting it, we either have to guess, or go through the hassle of copying your code and compiling it ourselves. Your job, as the asker of the question, is to make it as easy as possible for me to answer it.
edit: It is probably not a good idea to make your own class called ArrayList since there already is such a class as part of the API. It may work, but you are setting yourself up for confusion.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
First of all as correctly pointed out by 'Rob', your classname has to be changed into something as per the standard Java cosing practice. [Should not be 'ArrayList']
I have changed the classname and able to compile and execute the program successfully,
“Men are only as good as their technical development allows them to be.”
Joined: Jul 15, 2011
Thank you Fred, Rob and Joydeep.
I've been trying to name these tutorial files something that will tell me what's in them for future use. It never occurred to me that I'd be creating a confilct.
Fred, Sorry for not including my error message. I'll be sure to do that in the future.
Renamed my class and got it to work. Something interesting is that I had to change my import from 'java.util.*' to 'java.util.ArrayList' to get it to compile. I thought that 'java.util.*' meant to load in all utilities?