File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Problem using ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Problem using ArrayList" Watch "Problem using ArrayList" New topic
Author

Problem using ArrayList

Fernando Piovani
Greenhorn

Joined: Feb 09, 2011
Posts: 10
hi folks, iam having trouble using the method add from ArrayList.

My program consists in parsing and loading information from a xml file containing gps coordinates to memory.



Where 'nd' is a object of a class Nodes. And 'via' from Way class:



So a way its composed of several nodes (if its not a straight line). The problem of the code is that should load a way to the memory, along with its nodes. But for some reason, the add method of ArrayList its only adding the last element of the nodes list.



With this xml example:



So the exit of the program goes as:

Lat: -21.7879189
Lat: -21.7883913
Lat: -21.7883908
Lat: -21.7879178
-21.7879178
-21.7879178
-21.7879178
-21.7879178

When it should goes like this:

Lat: -21.7879189
Lat: -21.7883913
Lat: -21.7883908
Lat: -21.7879178
-21.7879189
-21.7883913
-21.7883908
-21.7879178


What is wrong?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

It looks like you are using the same object repeatedly, instead of creating a new object for each set of data. My guess would be the variable named "nd".
Fernando Piovani
Greenhorn

Joined: Feb 09, 2011
Posts: 10
Paul Clapham wrote:It looks like you are using the same object repeatedly, instead of creating a new object for each set of data. My guess would be the variable named "nd".


yeah, i've used nd=new Nodes(); under the .add method and it works. Thanks for poiting that out dude.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem using ArrayList
 
Similar Threads
Create a tree from a resultset
Parse large xml files
Save XML nodes in a String array for ChooseNodes
Field 'ID' doesn't have a default value: org.hibernate.exception.GenericJDBCException: could not ins
java.sql.SQLException: Connection handle has been closed and is unusable