7 Replies Latest reply on Dec 18, 2001 12:56 AM by 843797

    Hashtable Exception

    843797
      Hi all,
      I'm in a big trouble.I have this exception and i have not found any solution ,yet.Could anybody help me please...
      Thank you...

      Exception occurred during event dispatching:
      java.lang.NullPointerException
      at java.util.Hashtable.get(Unknown Source)
      at java.awt.Component.getFontMetrics(Unknown Source)
      at javax.swing.text.WrappedPlainView.updateMetrics(Unknown Source)
      at javax.swing.text.WrappedPlainView.setSize(Unknown Source)
      at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(Unknown Source)
      at javax.swing.plaf.basic.BasicTextUI.modelToView(Unknown Source)
      at javax.swing.text.DefaultCaret.repaintNewCaret(Unknown Source)
      at javax.swing.text.DefaultCaret$1.run(Unknown Source)
      at java.awt.event.InvocationEvent.dispatch(Unknown Source)
      at java.awt.EventQueue.dispatchEvent(Unknown Source)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)

      at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
      at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
      at java.awt.EventDispatchThread.run(Unknown Source)
        • 1. Re: Hashtable Exception
          843797
          In what situation does this exception occur?

          Hashtable probably doens't have any bugs, so the nullpointer exception is caused when hashtable tries to recieve hashcode of null key provided by getFontMetrics-method. FontMetrics queries a hashtable with the font parameter it's provided. Tracing backward more java api source we end up having that WrappedPlainView.getContainer().getFont() returns null... does this help?

          Somebodys finding the host componets font for some reason, but it seems to be null.
          • 2. Re: Hashtable Exception
            843797
            Hashtable does not support null keys and null values. If you need such a feature, go for the HashMap class (which like Hashtable implements the Map interface) but support both cases. Also note that Hashtable is thread safe, HashMap is not. You can make any Map thread safe using Collections.synchronizedMap.

            All the classes I named are from the java.util package.
            • 3. Re: Hashtable Exception
              843797
              Hashtable does not support null keys and null values.
              If you need such a feature, go for the HashMap class
              (which like Hashtable implements the Map interface)
              but support both cases. Also note that Hashtable is
              thread safe, HashMap is not. You can make any Map
              thread safe using Collections.synchronizedMap.

              All the classes I named are from the java.util
              package.
              This is not the issue here. Look at the stack trace more carefully. Should reprogram the Component-class to support HashMap?
              • 4. Re: Hashtable Exception
                843797
                First of all, thanks for your answers.

                In fact i don't use the hashtable class, this exception occured when one of my combo box selected.I used try-catch blocks but i cant catch the exception.I hope,i'm not wrong about what you explain.
                Thanks...


                • 5. Re: Hashtable Exception
                  843797
                  You could try to post this to swing forum... all I can tell that the comboboxes parent/host has a null font. Can you check that?`
                  • 6. Re: Hashtable Exception
                    843797
                    Also, did you tried to paint/use your combo box before it became visible, and thus maybe got a problem with properties lazily loaded (such as the font for example, that might only be loaded on the 1st combo box being visible).

                    Also did you played with the setup of your JDK? what JDK are you using under which OS?

                    About having your try/catch not catching the exception, this comes from the fact the exception is not raised in the thread running this try/catch block but in the event dispatching thread. Also try to indentify when the exception is raised (just by passing the mouse over, by giving the focus, is it raised only once).
                    • 7. Re: Hashtable Exception
                      843797
                      hii,
                      Finally,I have solved the problem.
                      In fact when i click a button, I remove all the components on my panel and then add the new components on it.But when I remove the JTextField object with remove(Component) function, the problem occures somehow.
                      anyway, thanks for your helps.