Salve a tutti ho un problema di cui non riesco a uscirmene....
ho una funzione che setta i campi di un array di oggetti tramite un ciclo, il problema è che all'uscita del ciclo uno dei campi viene settatto a tutti con lo stesso valore dell'ultima iterazione!!!
Mi spiego meglio il campo data viene settatto a tutti con la data dell'ultimo utente.
Codice MOLTO semplificato!
codice:Class Date{ .... } Class User{ String name; ... Date birthDate; } Class Test{ ... org.jdom.Element el = null; private static User[] five = new User[5]; Iterator cursor = ...; while( cursor.hasNext() ){ el = (Element)cursor.next(); five[current] = new User( el.getAttributeValue("nome"), el.getAttributeValue("pw"), el.getAttributeValue("card") ); // Info aggiuntive tmp = el.getChild("info"); //tmpDate = new Date(tmp.getAttributeValue("birthDate")); five[current].setRealInfo( tmp.getAttributeValue("realName"), tmp.getAttributeValue("realSurname"), tmp.getAttributeValue("birthDate") ); current++; tmp = null; tmpDate = null; } return five; }

Rispondi quotando