TreeMap -  Comparator how to get it to work

Hi All,
I am a newbie java programmer. Ik trying to understand de TreeMap en Compator and objects. I got some questions maybe that someone could help me.
I have a class Customer:
import java.util.TreeMap;
import java.util.Set;
import java.util.Iterator;
import java.util.Collection;
import java.util.Map;
public class Customer
     private TreeMap customertable = new TreeMap();
     public void put(Object key, String value)
          // Record subscriber
          customertable.put(key,value);
     public Abonnee get(String key) // Abonnee in english means subscriber
          return (Abonnee)customertable.get(key);
     public void remove(String key)
          customertable.remove(key);
and a comparator class like:
import java.util.*;
class Vergelijk implements Comparator
     public int compare(Object obj1, Object obj2)
     String str = (String)obj1;
     return str.compareTo((String)obj2);
public boolean equal(Object obj)
     return obj == this;
How do i get the Customer class working with the Vergelijk class (comparator) which statements do i have to add and in which class?
My program can add a object but when i add a second object i get a errors like:
java.lang.ClassCastException: Abonnee
at java.util.TreeMap.compare(TreeMap.java:1081)
at java.util.TreeMap.put(TreeMap.java:459)
at Klanten.put(Klanten.java:33)
at GuiVb.toeVoegen(GuiVb.java:84)
at GuiVb.actionPerformed(GuiVb.java:152)
at java.awt.Button.processActionEvent(Button.java:381)
at java.awt.Button.processEvent(Button.java:350)
at java.awt.Component.dispatchEventImpl(Component.java:3598)
at java.awt.Component.dispatchEvent(Component.java:3439)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:197)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
hope get some good hints.

Maestro, you may want to change you the put method in the Klanten class to public void put(String key, value)
    klantentabel.put(key, value);
}and then replace any occurances of
klant.put(p, p.getNaam());with
klant.put(p.getNaam(), p);Why?
Quote from http://java.sun.com/j2se/1.4.1/docs/api/java/util/TreeMap.html
"This class guarantees that the map will be in ascending key order, ..."
So, if use Strings as keys, you don't need to write your own comparator, since Strings are already comparable.
You did use your Abonne object as key and its name as value when putting data into the map, but on retrieval and deletion you did use Abonne's name as key => obviously can't work (i.e. no matching entry will ever be found).
If you do not understand the concepts of Maps, refer to
http://java.sun.com/j2se/1.4.1/docs/api/java/util/Map.html

Similar Messages

  • I have purchased itunes match but the cloud will not load on my ipad 4.the only music that will show up is stuff that i bought from the itunes store.any ideas on how to get this to work?

    i have purchased itunes match but the cloud will not load on my ipad 4.it works on my iphone 5 & it originally worked on my ipad.the only music that will show up is stuff that i bought from the itunes store.any ideas on how to get this to work?

    On the MBP, in iTunes, switch to Song view and enable the iCloud Status column by pulling down View > View options and selecting the option for "iCloud Status." Close the small window. Look for any tracks that have a status of "waiting." If you see several of them disable iTunes Match while holding down the Option key. Quit iTunes, wait a few seconds, then open it again and turn iTM back on. Let it compelete the scan. Wait until all tracks that are "waiting" have a status of either "matched" or "uploaded."
    On the iPad, turn off iTunes Match then launch the Music app and let the contents clear out. Power cycle the iPad for good measure, then re-enable the service once all the tracks in iTunes have been processed.

  • When I switch my time capsule to 5.0ghz mode the range of my wireless network drops significantly.  Near the Time Capsule my Macbook Pro works fine, in my bedroom I have almost no signal.  In mixed mode it works fine.  Any ideas on how to get 5.0 working?

    When I switch my time capsule to 5.0ghz mode the range of my wireless network drops significantly.  Near the Time Capsule my Macbook Pro works fine, in my bedroom I have almost no signal.  In mixed mode it works fine both placed.  Any ideas on how to get 5.0 working?  I thought 5.0Ghz was supposed to have a wider range.  Do I need to change a setting on the Macbook Pro?
    Thanks, W

    I'm not sure if you understand that 5 GHz has some upsides, but also some very significant downsides.
    The upside is that the 5 GHz signal will allow faster speeds.
    The downside is that you must always give up something in order to gain something else.Unfortunately, the marketing hype about 5 GHz does not go into very many details about this.
    In the case of 5 GHz, the 5 GHz signals are much weaker than 2.4 GHz signals, so they do not travel as far or penetrate any obstructions like walls or ceilings nearly as well as 2.4 GHz signals. In many cases, in order to get good 5 Ghz performance, you literally have to have almost a line-of-sight relationship between your computer and the wireless router.
    If you have a new dual band router, which broadcasts both a 2.4 GHz and 5 GHz signal simutaneously, your Mac will connect to the best signal quality automatically depending on its location in relation to the router. In the same room, without any obstructions, it will connec to 5 GHz. But, take the laptop down the hall a few rooms and around the corner and the Mac will connect to the 2.4 GHz signal because at that location, the 2.4 GHz signal is not only stronger, it is also faster.

  • ITunes wont open for me. it keeps saying "the Disc "untitled playlist" cannot be read. An unknown error occurred (-69)." don't know how to get it to work. Please help

    iTunes wont open for me. it keeps saying "the Disc "untitled playlist" cannot be read. An unknown error occurred (-69)." don't know how to get it to work. Please help

    It is likely a hardware failure
    http://support.apple.com/kb/TS3694?viewlocale=en_US#error1

  • Has anyone figured out how to get speech recognition working with sticky keys enabled on mountain lion?

    I'm trying to use speech recognition to input text on my iMac running the latest mountain lion, 10.8.3.
    I have sticky keys enabled.
    When I try to start speaking by pressing the function key twice nothing happens. I can only get it to work if I disable sticky keys.
    The same problem occurs with all the other modifier keys as shortcut, they do not work with sticky keys.
    When I try to select a different shortcut, I am unable to select a two key combination, but am limited to one.
    If I select the F6 key, or any other single key, I am able to start speech recognition. However the second time that I press the key, it does not stop recognition and process my words. Instead, it restarts the recognition.
    Has anyone figured out how to get speech recognition working with sticky keys enabled?
    Or a way to get an individual key shortcut to start on the first press and process it on the second?
    Or a way to get key combinations to work, as specified by the help:
    Dictation On and Off
    To use Dictation, click On.
    When you’re ready to dictate text, place the insertion point where you want the dictated text to appear and press the Fn (function) key twice. When you see the lighted microphone icon and hear a beep, the microphone is ready for you to speak your text.
    Shortcut
    By default, you press the Fn (Function) key twice to start dictation. If you like, you can choose a different shortcut from the menu.
    To create a shortcut that’s not in the list, choose Customize, and then press the keys you want to use. You can press two or more keys to create your shortcut.

    I noticed with version 10.8.4 of OS X that I am now able to select F6 to activate, and the return key to complete the speech recognition. This is still different than the description of how these should function that's included in the help, but at least it's an improvement.

  • I just got the iphone 4s and i cant figure out how to get siri to work it seems to be the old voice command. HELP!

    i just got the iphone 4s and i cant figure out how to get siri to work it seems to be the old voice command. HELP!

    Did you enable Siri in settings?
    Settings > General > Siri > ON
    If Siri is off, all you get when pressing the home button for 1 second is the old Voice Control.

  • Facebook like button is not working, I have used the muse widget and created code from facebook. Does anyone know how to get this to work?

    Facebook like button is not working, I have used the muse widget and created code from facebook. Does anyone know how to get this to work?

    Hi connally25,
    Below is a link to a video tutorial on how to add a Facebook Log button, please check if you have followed the same steps to add the video.
    http://tv.adobe.com/watch/learn-adobe-muse-cc/adding-a-facebook-like-button/
    If you have followed the steps correctly and the button still does not work; here is a link to a forum thread which might help solving the issue:
    Facebook Follow Widget not working
    Regards
    Sonam

  • I have updated to OS X 10.9 and now can't open Aperture, message reads You can't use this version of the application "Aperture" with this version of OS X. You have "Aperture" 3.2.3... all i need to know is how to get Aperture to work again..help !

    I have just updated to OS X 10.9 and now find that I can't open Aperture to access photos etc, message reads : You can't use this version of the application "Aperture" with this version of OS X. You have "Aperture" 3.2.3... whichj is not a lot of help, i have limited technical ability and all i need to know is how to get Aperture to work again...help !

    Software Update?

  • I have a 4s iPhone which I loaded the new Os on last night. Now I can not connect to iTunes. A message comes up saying i need 10.6.3 or later but I am running 10.6.1 as I have an older Mac. Anyone have ideas how to get this to work?

    I have a 4s iPhone which I loaded the new Os on last night. Now I can not connect to iTunes. A message comes up saying i need 10.6.3 or later but I am running 10.6.1 as I have an older Mac. Anyone have ideas how to get this to work?

    Its not telling you to update your iPad, its telling you you need to download a recent version itunes on your computer.
    Go here to download the newest version of iTunes.
    http://www.apple.com/itunes/?cid=OAS-US-DOMAINS-itunes.com

  • How to get Google Gmail working in Yosemite? (not just in Mail)

    How to get Google Gmail working in Yosemite? Mail is working. Gmail is coming to Mail.  I want to use gmail in Google on the web as I have in the past.

    MrAtheist wrote:
    It's even an irony that this forum doesnt work on safari at all. All the buttons are just ... buttons. Nothing works when you click on it (i.e. filtering, tagging, etc).
    Even more ironic is the fact that I use nothing but Safari, and it works correctly in Gmail, as well as on this site.

  • How to get WLAN card working on Tecra M1?

    I just bought a Tecra M1, 2nd Hand. Great! There is XP installed but no Toshiba tools. I can't manage to get access to my WLAN router. Seems as if the WLAN connection isn't installed yet. As I know from my Satellite Pro M30, there are Toshiba tools for that, they work smart.
    Maybe I would need the drivers - WXP finds unknown hardware during start up - could be the WLAN device - who knows.
    When I check the network connections, I find 1934 and LAN adapter, but no WLAN device. I already ran the XP assistant for WLAN connections, entered SSID and hex Key; but no WLAN device shows up.
    So, has anybody an idea how to get the WLAN working?
    Is there a possibility to get the M1 Toshiba Software or can I use my SatPro Software?
    Thanks so far Jan

    My question seems to be difficult... No reply at all
    But keeping on searching I found some links to other Toshiba sites
    There I found the required drivers for the WLAN
    Once the driver is installed, the WLAN device was proper configurable.
    The second hardware device that was found and specified as unknown, was the IR Device. I took a driver from my SatPro CD. All fine so far.
    By that way: I couldnt find the utilities for download, but I tries to uses the SatPro CD - that works
    Hoping that my experiences will help somebody else I mark my question as being answered.
    So far Jan

  • Mozilla Fire Fox 4, Bookmark Toolbar, how to get it to work?

    Mozilla Fire Fox 4, Bookmark Toolbar, how to get it to work?

    Hi,
    the bookmarks toolbar is blank, it can be turned on or off, but the bookmarks, which are in the toolbar folder when I view all my bookmarks, don't appear in the toolbar. This is when using windows xp. When using windows 7 at home, it works fine. thanks.

  • My itunes store won't open. Any suggestions on how to get this to work? I've already downloaded the newest version of itunes. I'm also not sure what Mac operating system I have..

    My itunes store won't open. Any suggestions on how to get this to work? I've already downloaded the newest version of itunes. I'm also not sure what Mac operating system I have..

    To find the version of Mac OS X on your computer, all you have to do is click the Apple logo and then About this Mac. For more info, take a look at this doc -> Finding your OS X version and build information
    Do you see an error when you try to open the iTunes Store on your Mac?
    This Apple doc is a good place to start -> iTunes: Advanced iTunes Store troubleshooting

  • Does anyone know how to get funshion to work on an ipad

    does anyone know how to get funshion to work on an ipad

    There is an Fee app you can download

  • I'm trying to connect my iPad to my Samsung galaxy s by bluetooth but the ipad will pair with it but not connect and says "its not supported" does anyone know what this means and how I get it to work?

    I'm trying to connect my iPad to my Samsung galaxy s by bluetooth but the ipad will pair with it but not connect and says "its not supported" does anyone know what this means and how I get it to work?

    iOS devices do not have the BT profiles that support file sharing and othr general functions. See:
    iOS: Supported Bluetooth profiles
    Basically it support headphones, keyboards, speakers, peer-to-peer gaming

Maybe you are looking for

  • Why is usbConnectToCam-USBDeviceOpen flooding my system.log on OSX and slowing my internet browsing [SOLVED]

    I get like 30 of these at a time as I load random pages. Any idea how to stop this? Thanks Jim 12/15/10 1:42:18 PM [0x0-0x3a03a].org.mozilla.firefox usbConnectToCam-USBDeviceOpen: Error: kIOReturnExclusiveAccess - exclusive access and device already

  • Diese Seriennummer ....

    Diese Seriennummer ist für dieses Produkt nicht gültig - bekomme ich als Fehlerangabe, wenn ich die von Adobe zugeteilte Seriennummer eingebe bei der Installation der ersten CD der Creative Suite 5 Design Premium Student and Teacher Edition. Wer kann

  • Rman job in OEM

    Hi All, This is my requirement. I want to execute below rman script in all the databases we monitor. After that we are thinking of creating UDM to poll against v$database_block_corruption and alert for any corruption. RMAN> backup validate check logi

  • Why does email announcement give wrong URL (iWeb 3.0.2)

    I just completed the first draft of a new site, hosted on mobileMe, using the latest version of iWeb 09, 3.0.2. I accepted the invitation for the program to generate an announcement email, but the URL it generated just pointed to my generic web addre

  • Why do I get the 'PowerPC code' error when trying to launch an Intel-based app from a CD?

    When trying to launch a Flash-based app from a CD on my Mac Book Pro, I get the "PowerPC apps are no longer supported" error. Yet the app is not built with PowerPC code. This also happened with Microsoft Office programs soon after I upgraded to OSX L