• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem using ArrayList  RSS feed

 
Fernando Piovani
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!