Ciao a tutti, se utilizzo la seguente classe:
Aggiungendo e iterando allo stesso tempo mi viene lanciata questa eccezione: ConcurrentModificationExceptioncodice:public class Result extends ArrayList { private Iterator i; public Result() { super(); i = this.iterator(); } void addArrayResult(Value v[]) { for(int i = 0; i < v.length; i++) this.add((Value)v[i]); } void addArrayResult(String v[]) { for(int i = 0; i < v.length; i++) this.add((String)v[i]); } void addResult(String r) { this.add((String)r); } void addResult(Value r) { this.add((Value)r); } public boolean hasNext() { return i.hasNext(); } public String next() { try { return i.next().toString(); } catch(NoSuchElementException ex) { return null; } } }
La classe la uso così:
Qualcuno saprebbe dirmi come permettere un comportamento simile senza che venga lanciata questa eccezione?codice:public class TestLoad { public static void main(String[] args) { try { Result r = null; Result cR = null; Connection c = Connection.connectTo("Test"); r = c.execQuery("getAllTabs"); String str; while(r.hasNext()) { str = r.next(); System.out.println("Tabella " + str); cR = c.execQuery("selectTab " + str + "\n" + "getAllFields"); while(cR.hasNext()) { System.out.println(cR.next() + "\t"); } } c.close(); } catch(DBException e) { e.printStackTrace(); } } }
grazie

grazie
Rispondi quotando