Results 1 to 5 of 5
  1. #1
    PuppetJacks is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default What am I missing here?

    Ok, hey, - I'm hoping someone can asist me with this? - I'm essentially writing a music library database, whereby all the tracks(with artist & title details in local variables) are loaded into one single musicLibrary collection.

    When I want to update the JLists on the interface I'm using the below method to retrieve the full catalogue of tracks, then separate them into a TreeMap using the artist as the key & the associated tracks into an arraylist as the value.

    for some blasted reason though it's writing the tracks multiple times. i.e, ACDC only has 3 songs, yet it presents the 3 songs 3 times, (so theres 9 songs!, 3 copies of each in the order 1,2,3,1,2,3,1,2,3) and if i click on different artists, that number seems to increase leading me to believe it's something to do with my gui calling the setListData() method.

    some Println statements have revealed that the ArrayList being passed to the gui starts off too big, so it's obviously something to do with my iteration in the setListData() method. - If anyone can clearly see what I'm buggering up, please let me know as I'm going blind looking at this.

    Thanks in advance

    Here's my setListData() method within my mainLibrary Class.

    Java Code:
        public TreeMap<String, ArrayList<Track>> getListData()
        {
        TreeMap<String, ArrayList<Track>> temp = guiTracks;
        ArrayList<Track> trackList = new ArrayList<Track>();
            for(Track t : mainLibrary)
            {
                if(temp.containsKey(t.getArtist()))
                {
                    trackList = temp.get(t.getArtist());
                    trackList.add(t);
                }
                else
                {
                    trackList = new ArrayList<Track>();
                    System.out.println(t.getArtist());
                    trackList.add(t);
                }
    
            temp.put(t.getArtist(), trackList);
            }
        guiTracks = temp;
        return guiTracks;
        }
    And here's the method in my gui which requests the TreeMap & updates the JLists..
    Java Code:
        public void setTrackList()
        {
            TreeMap<String, ArrayList<Track>> listItems = library.getListData();
            ArrayList<Track> tracks = listItems.get(artistList.getSelectedValue());
            ArrayList<String> allTracks = new ArrayList<String>();
            for (Track t : tracks)
            {
                allTracks.add(t.getTitle());
            }
            trackList.setListData(allTracks.toArray());
            Track nextOne = library.getNextTrack();
            String nextFull = nextOne.getArtist() + " - " + nextOne.getTitle();
            lblNextTrack.setText(nextFull);
            this.getContentPane().repaint();
        }
    The creation of guiTracks (used in getListData) is in the below method, which sets up the main Arraylist of all tracks.

    Java Code:
        private void addToLibrary(Track thisTrack)
        {
        mainLibrary.add(thisTrack);
        Set<String> tempArray = guiTracks.keySet();
        if(tempArray.contains(thisTrack.getArtist()))
            {
            ArrayList tracks = guiTracks.get(thisTrack.getArtist());
            tracks.add(thisTrack);
            guiTracks.put(thisTrack.artist, tracks);
            }
        else
        {
            ArrayList<Track> tracks = new ArrayList();
            tracks.add(thisTrack);
            guiTracks.put(thisTrack.artist, tracks);
        }
        }
    Any help greatly appreciated.

    - PJ.
    Last edited by PuppetJacks; 06-30-2012 at 05:08 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: What am I missing here?

    Continue adding println statements so you see what the computer sees and also so you see the results of what the computer is doing.

    Hard to test without code that compiles, executes and shows the problem.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    PuppetJacks is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

    Default Re: What am I missing here?

    cheers, - I'm trying to suss it out, it's just excrutiatingly hard to do. - I appreciate it was a long shot with just those methods posted, but I guess I was hoping someone might spot some fundamental issue with my for loops that was causing the recurring Track submissions into my list.

    No problem. - I shall continue with my search. thanks for your help.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: What am I missing here?

    Quote Originally Posted by PuppetJacks
    What am I missing here?
    A decent subject line. Please go through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    PuppetJacks is offline Member
    Join Date
    Feb 2011
    Posts
    8
    Rep Power
    0

Similar Threads

  1. org.j3d is missing...
    By LinuxDev@Flanders in forum Java Gaming
    Replies: 3
    Last Post: 07-23-2012, 12:31 PM
  2. What am I missing here..?
    By andrew_smiley in forum New To Java
    Replies: 5
    Last Post: 02-22-2012, 01:47 PM
  3. Avatar missing?
    By DarrylBurke in forum Forum Lobby
    Replies: 5
    Last Post: 05-05-2011, 03:47 PM
  4. missing info
    By java-noob in forum New To Java
    Replies: 2
    Last Post: 04-20-2010, 09:55 AM
  5. is it bug? or am i missing a point?
    By blowguy in forum Threads and Synchronization
    Replies: 1
    Last Post: 11-20-2007, 06:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •