Note that there are some explanatory texts on larger screens.

plurals
  1. POAll elements of An ArrayList change when a new one is added?
    text
    copied!<p>First of all, apologies for not being able to supply any sourcecode. My project is pretty big and linking everything would be impractical, and I have not been able to scale down the problem which is exceedingly annoying. I will do my best to explain it here.</p> <p>I am dynamically creating new instances of a class on each loop in my code. This instance is dynamically given a couple of properties while in the loop, 'name' for example. At the end of each loop, the newly generated instance is added to an ArrayList held in a another, 3rd, class. </p> <p>The problem however is that when a new element is added, for whatever reason, all previous elements change to match exactly the latest. My guess is that the ArrayList is creating a reference to the dynamically created element so that whenever it changes, they all change, but I do not know how to fix this.</p> <p>I would be grateful for any advice and apologies again for the quality of this explanation. I will post any specific piece of the code you may wish to see</p> <p>As Requested - XmlHandler.java - <a href="http://pastebin.com/mGmWt1RD" rel="noreferrer">http://pastebin.com/mGmWt1RD</a> ParsedDataSet.java = <a href="http://pastebin.com/k1xb3KBe" rel="noreferrer">http://pastebin.com/k1xb3KBe</a> Content.java = <a href="http://pastebin.com/UxiL2f9q" rel="noreferrer">http://pastebin.com/UxiL2f9q</a></p> <p>Just to cut down on your comprehension time - The project is an epub reader. The XMLHandler is being called from a SAX parser in another class not shown. The XMLHandler is used 3 different times for 3 different XML sets so there is some clutter there. </p> <p>The problem lies with the 'toc' ArrayList. The 'toc', or TableOfContents, holds the Contents instances to be referenced later (not shown). I am trying to pass data each new instance of 'Content' and then pass that into the static ArrayList</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload