I am having trouble with an ArrayList that I am using, I substituted it for a loop with a regular array and now i am getting an error when I compile: "<identifier> expected." I've tried implementing the ArrayList in a variety of ways, but keep getting the same error. For clarification I am using BlueJ 2.2.1 on Mac OS X 10.5.2 Some of the other code may be wrong, but just because I've been moving everything around while tearing my hair out trying to find out what went wrong...
[ February 20, 2008: Message edited by: Joseph Carr ]
I understand. I'll try and be more clear, when I compiled this code in BlueJ it gives me a popup box that I cannot copy so I will type it word for word here:
It's blueJ so the error message is weird. I'd do it in Netbeans or Xcode but I cannot get either of them to compile a single class for some reason...
When you want to "do" something (like add elements to a List), these statements need to go inside a method body.
I'd like to initialize this ArrayList immediately, the other ArrayList (gameStatIntArrayList) will be more dynamic so i'll be initializing it inside of a method. I can still use the while loop on an Array ratehr than implementing this ArrayList, I just thought that this was the more efficient way to go....four hours later... [ February 20, 2008: Message edited by: Joseph Carr ]
Thanks Bear. I don't thinkn the compiler liked me trying to add stuff into ArrayList outside of a method. Another snafu was using an integer type in an ArrayList (superfluous and just plain wrong). So I just created an initializer method that I have to run before the other methods will work. Thanks for all your help, it was really simpler than I was making it (usually the case).
Don't declare a generic object and then instantiate it with a non-generic reference. That is called using a raw type, which for reasons I have forgotten is very much frowned upon. In fact Sun keep threatening to upgrade it to a compiler error.
The correct syntax would be List<Integer> myList = new ArrayList<Integer>();
crispy bacon. crispy tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss