I'm having one of those "Can't see the forest for the trees" moments. I need someone to point out the error of my ways. I'm reading in a ZIP file which contains four files:
keygen_1.0.jar
pnskeywords.dat
keygendep.jar
pns_plugin.xml
I'm reading in the last one named pns_plugin.xml. It looks like this:
I am working with two classes: PluginEntry and PluginHandler. See classes below. When I run the following code:
Note the iteration over the ArrayList. When this prints out it looks like this:
What this tells me is that keygendep.jar is the last element read in from the xml file and when class PluginHandler adds each new PluginEntry to the ArrayList, it is overwriting all the elements in the list with the same last element information. I can't figure out why that is? I've gone over the code in DEBUG mode in Eclipse but nothing jumps out at me as to what is going wrong. The println statements tell the tale in the character() method. Everytime I create a new instance of PluginEntry, I also print out the values of the previous PluginEntry from the ArrayList. The previous one is definitely being overwritten. The problem must lie in the PluginHandler class somehow. Please advise.
Alan Shiers wrote:when class PluginHandler adds a new PluginEntry to the ArrayList it is overwriting all the elements in the list with the same last element information.
As soon as I saw this I knew I was searching for the word "static". And sure enough, your class-level variables in PluginEntry are declared static. So all PluginEntry instances share the same value of name and destination folder.
Alan Shiers
Ranch Hand
Joined: Sep 24, 2003
Posts: 216
posted
0
Damn your good! You were right. I got rid of the "static" declarations in PluginEntry. It worked fine after that. Lesson learned.