ArrayList, Point2D, size() - 1
Hi,
I am storing various coordinates in an ArrayList; I would like to store the last 2 coordinate-pairs in variables:
private List<Point2D> allPlayerCoordinates =new ArrayList<Point2D>();
private Point2D playerCurrentPosition, playerLastPosition;
(...)
// doesn't work: "Type mismatch: cannot convert from int to Point2D"
playerLastPosition = allPlayerCoordinates.size() - 1;
I don't know how to store the last 2 coordinates in variables... and I don't understand the error message I get because all variables are declared as Point2D...?
Thanks!
Edit: I am sorry, the posting should be in "Java Programming"
[814 byte] By [
SFLa] at [2007-11-27 5:38:12]

# 1
> > private List<Point2D> allPlayerCoordinates = new
> w ArrayList<Point2D>();
> private Point2D playerCurrentPosition,
> , playerLastPosition;
>
> (...)
>
> // doesn't work: "Type mismatch: cannot convert from
> int to Point2D"
> playerLastPosition = allPlayerCoordinates.size() -
> 1;
>
> I don't know how to store the last 2 coordinates in
> variables... and I don't understand the error message
> I get because all variables are declared as
> Point2D...?
>
this results in an integer, not a Point2D.
allPlayerCoordinates.size() - 1;
You probably need this integer to get the index position of the Point2D object of interest in your List.
Have you tried something like this?:
playerLastPosition = allPlayerCoordinates.get(allPlayerCoordinates.size() - 1);
For reference, click on this [url=http://java.sun.com/j2se/1.5.0/docs/api/java/util/List.html]link[/url] to read information on the Java specification for the List interface. Check out the get(int index) method in particular. Good luck!
Message was edited by:
petes1234