Results 1 to 5 of 5
Thread: What am I missing here?
- 06-30-2012, 05:03 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
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.gif)
Here's my setListData() method within my mainLibrary Class.
And here's the method in my gui which requests the TreeMap & updates the JLists..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; }
The creation of guiTracks (used in getListData) is in the below method, which sets up the main Arraylist of all tracks.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(); }
Any help greatly appreciated.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); } }
- PJ.Last edited by PuppetJacks; 06-30-2012 at 05:08 PM.
- 06-30-2012, 05:23 PM #2
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.
- 06-30-2012, 05:37 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
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.
- 06-30-2012, 08:29 PM #4
Re: What am I missing here?
A decent subject line. Please go through the Forum Rules -- particularly the third paragraph.
Originally Posted by PuppetJacks
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 07-01-2012, 11:16 AM #5
Member
- Join Date
- Feb 2011
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
org.j3d is missing...
By LinuxDev@Flanders in forum Java GamingReplies: 3Last Post: 07-23-2012, 12:31 PM -
What am I missing here..?
By andrew_smiley in forum New To JavaReplies: 5Last Post: 02-22-2012, 01:47 PM -
Avatar missing?
By DarrylBurke in forum Forum LobbyReplies: 5Last Post: 05-05-2011, 03:47 PM -
missing info
By java-noob in forum New To JavaReplies: 2Last Post: 04-20-2010, 09:55 AM -
is it bug? or am i missing a point?
By blowguy in forum Threads and SynchronizationReplies: 1Last Post: 11-20-2007, 06:19 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks