This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

require another set of eyes to look at my code

 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

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:

    PluginEntries:
    Name: keygendep.jar Destination Folder: C:\PNS_1.0\ZipInstaller\lib
    Name: keygendep.jar Destination Folder: C:\PNS_1.0\ZipInstaller\lib
    Name: keygendep.jar Destination Folder: C:\PNS_1.0\ZipInstaller\lib

    It should look like this:

    PluginEntries:
    Name: keygen_1.0.jar Destination Folder: C:\PNS_1.0\ZipInstaller\plugins
    Name: pnskeywords.dat Destination Folder: C:\PNS_1.0\ZipInstaller
    Name: keygendep.jar Destination Folder: C:\PNS_1.0\ZipInstaller\lib

    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

     
    Paul Clapham
    Sheriff
    Pie
    Posts: 20959
    31
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 237
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Damn your good! You were right. I got rid of the "static" declarations in PluginEntry. It worked fine after that. Lesson learned.

    Thanks,

    Alan
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic