Bonjour,
J'ai une classe qui stockent des attributs, un attribut borne et borneInitiale. Avant l'execution d'un traitement, je copie borne dans borneInitiale. Le set fait juste borneInitiale=borne.
Pendant le traitement, borne est modifié et à ma grande stuppeur, borne initiale aussi. J'en déduit que tous les deux pointent au méme endroit en mémoire non?
Comment faire une copie undépendante de mon attribut?
J'ai essayé ceci:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 public void setBornesBak(Vector bornesInitBak){ Object o; Iterator iter =bornesInitBak.listIterator(); while (iter.hasNext()){ o = iter.next(); this.bornesInitiales.addElement(o); } }
mais le programme plante comme si le vecteur que j'envoie en paramètre étaut vide (ce qui n'est pas le cas).
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at metier.Attribut.setBornesBak(Attribut.java:149) at gui.DetailAttr.actionPerformed(DetailAttr.java:361) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
Partager