Results 1 to 4 of 4
Thread: trouble with ArrayList
- 09-29-2011, 11:09 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 38
- Rep Power
- 0
trouble with ArrayList
I hope my code (below) is self-explanatory. The compiler doesn't like it, though. It says:
"cannot find symbol
symbol: method getX()
location: class java.lang.Object"
I don't get it. getX() is definitely a method of the class Point2D.Double, so what's the problem?
Please help. Thanks.
Java Code:ArrayList testList = new ArrayList<Point2D.Double>(2); testList.add(new Point2D.Double(3,5)); testList.add(new Point2D.Double(4,6)); messageBox4.setText( // messageBox4 is a JTextArea "testList.size() is: " + testList.size() + "\n" + "firstPoint.x: " + testList.get(0).getX() );
-
Re: trouble with ArrayList
While you have created a generic ArrayList<Point2D> object (no need for the Double part), you don't have a generic ArrayList<Point2D> variable, and so the compiler won't know that it holds Point2D objects. Make the variable generic too.
- 09-30-2011, 12:17 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 38
- Rep Power
- 0
Re: trouble with ArrayList
(Feel quite stupid now - the answer was pretty obvious, but just couldn't see it.)
Thanks. Your answers are always remarkably quick, thorough and clear.
-
Similar Threads
-
ArrayList copy some of the element from one arraylist tnto another arraylist
By ralf in forum New To JavaReplies: 12Last Post: 07-07-2011, 08:49 PM -
how to add Arraylist filter for a jsp page showing results from a servlet-Arraylist
By alok_sharma in forum Java ServletReplies: 7Last Post: 11-22-2010, 01:26 PM -
arraylist trouble
By Reiyn in forum New To JavaReplies: 9Last Post: 05-27-2009, 11:03 PM -
Trouble with ArrayList
By John D. in forum New To JavaReplies: 4Last Post: 03-18-2009, 07:43 PM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks