Results 1 to 5 of 5
  1. #1
    Okay123 is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default Extracting Keys from Hashtable fails

    Hello!

    To cut a long story short:

    I'm trying to iterate through an hashtable and therefore i want to extract the keys of it.

    But both...

    Set<String> set = hashtable.keySet();

    and

    Enumeration e = hashtable.keys();

    fail in a very strange way. My program doesn't crash oder something like that (started in eclipse btw.), I just get the following errormessage on the console.
    Maybe it has something to do with Swing? I cannot reproduce the error in a console app, but I only tried it once, so don't pay too much attention on this hint.

    The error:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at Feed.addItems(Feed.java:32)
    at Gui.update(Gui.java:204)
    at Gui.access$0(Gui.java:170)
    at Gui$2.actionPerformed(Gui.java:53)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    By the way, "at Feed.addItems(Feed.java:32)", this is the position of keys()/keyset() in my code.


    Thank you!
    Last edited by Okay123; 05-14-2010 at 09:35 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,524
    Blog Entries
    7
    Rep Power
    20

    Default

    Look carefully at line #32 of your Feed class; there's an object there that is null while it shouldn't be and your code is dereferencing it.

    kind regards,

    Jos

  3. #3
    Okay123 is offline Member
    Join Date
    May 2010
    Posts
    2
    Rep Power
    0

    Default

    I lost sight of the forest for the trees, thank you!

  4. #4
    personal's Avatar
    personal is offline Member
    Join Date
    May 2010
    Location
    NY
    Posts
    9
    Rep Power
    0

    Default

    this one is hard to debug just from your code and stack trace. try extracting your code out to a small program, run it again and see if that fails. best guess is that its not a problem with iterating through the ketset but a concurrent problem thats masking the issue

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,009
    Rep Power
    20

    Default

    I wouldn't say it's hard to debug.
    The NPE is occurring on those lines, so something (as Jos says) in those lines is null and being dereferenced.

    And there's only one thing that can be.

Similar Threads

  1. connection fails
    By jrjan in forum Advanced Java
    Replies: 3
    Last Post: 01-10-2009, 12:15 AM
  2. Over-riding purpose fails..
    By udayadas in forum New To Java
    Replies: 7
    Last Post: 08-24-2008, 04:14 AM
  3. Uisng primitive type values as keys for Hashtable
    By ravian in forum New To Java
    Replies: 3
    Last Post: 11-21-2007, 10:13 AM
  4. Repaint fails when using threads
    By rjevans2000 in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-21-2007, 11:22 PM
  5. Repaint fails when using threads
    By rjevans2000 in forum AWT / Swing
    Replies: 3
    Last Post: 08-15-2007, 05:42 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
  •