I'm not sure if the array list would be the best way to go, but I could be wrong..Have you tried just creating an array of the Item Objects? But of course then you couldn't add extra items at runtime.
By the way, is this getStartValue() method going to return different results for each Item?
I mean, would each of these return different values:
double amount = itemsList[0].getStartValue();
double amount2 = itemsList[1].getStartValue();
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
An ArrayList isn't an array. It (nor Vector which you shouldn't use, it's there for legacy use only) has different mechanisms.
To retrieve an item from your List use the get(index) method.
Under Java 1.5 (5.0, Tiger) you should thus do the following:
ArrayList<Item> itemsList = new ArrayList<Item>();
...
Item anItem = new Item();
...
itemsList.add(anItem);
double amount = itemsList.get(0).getStartValue();
Under older versions it's a bit different but not fundamentally so.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
I'm sorry, but why are you posting an answer to a question that is 18 months old, and, according to the OP's last response, is solved.
And your answer is wrong, I might add. You are attemtping to use array indexing into an ArrayList, which won't work, and is exactly the problem that was already solved in this thread.
masijade
Industrious Poster
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
and just as important as trying to give good advise is to try and word it in proper English.
1337 sp33ch and SMS shorthand are NOT proper English.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337