android - Java ArrayList .add() overwrites previous values -


i've checked out other people facing same issue, & of them instantiating objects want add outside loop. i'm doing inside while loop, i'm guessing that's not issue.

public arraylist<shmaptile> tiles = new arraylist<shmaptile>(); . . . private void parsexml(xmlpullparser parser) throws xmlpullparserexception, ioexception {     int eventtype = parser.geteventtype();     int = 0;      while ( eventtype != xmlpullparser.end_document )     {         string name = null;          switch ( eventtype )         {             case xmlpullparser.start_tag:             {                 name = parser.getname();                  if ( name.equalsignorecase("tile") )                 {                     shmaptile tile = new shmaptile();                     tile.gid = i;                      tiles.add(tile);                     system.out.println("gid: " + tiles.get(0).gid);                     i++;                 }                  break;             }              case xmlpullparser.end_tag:             {                 name = parser.getname();                  if ( name.equalsignorecase("data") )                 {                     this.runonuithread(new runnable() {                         public void run() {                             drawcurrentmapregion();                         }                     });                 }                  break;             }         }          eventtype = parser.next();     } } 

for debugging, attached counter each new object. when print out counter of first element in list, it's different. tried cloning. didn't work either.

as said in comments, field gid of class shmaptile static.

that means same value shared between all instances of class. if update one, updated in istances of class. remove static modifier , work


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -