This discussion is archived
14 Replies Latest reply: Sep 21, 2012 3:00 AM by jduprez RSS

Null pointer exception in jdk 1.7

953423 Newbie
Currently Being Moderated
Hi,

I am getting below exception while i am pressing the button to perform some action (moving from one page to other).

java.lang.NullPointerException
     at java.util.Hashtable.get(Hashtable.java:357)
     at javax.swing.KeyboardManager.registerKeyStroke(KeyboardManager.java:104)
     at javax.swing.JComponent.registerWithKeyboardManager(JComponent.java:2198)
     at javax.swing.JComponent.registerWithKeyboardManager(JComponent.java:2123)
     at javax.swing.JComponent.componentInputMapChanged(JComponent.java:2193)
     at javax.swing.ComponentInputMap.put(ComponentInputMap.java:94)
     at javax.swing.LookAndFeel.loadKeyBindings(LookAndFeel.java:439)
     at javax.swing.plaf.basic.BasicRootPaneUI.updateDefaultButtonBindings(BasicRootPaneUI.java:150)
     at javax.swing.plaf.basic.BasicRootPaneUI.propertyChange(BasicRootPaneUI.java:164)
     at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
     at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
     at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
     at java.awt.Component.firePropertyChange(Component.java:8382)
     at javax.swing.JRootPane.setDefaultButton(JRootPane.java:802)

The issue is the error is not coming regularly. But It comes. In jdk 1.6 with the same code i never faced this issue.


Thanks
  • 1. Re: Null pointer exception in jdk 1.7
    Jörg Explorer
    Currently Being Moderated
    Hello and welcome to the forum,

    posting the error stack is already a good start. But in order to help you, it's not sufficient.
    Please read this link.
  • 2. Re: Null pointer exception in jdk 1.7
    DarrylBurke Guru Moderator
    Currently Being Moderated
    950420 wrote:
    The issue is the error is not coming regularly. But It comes.
    Honor Swing's single threaded rule. All Swing constructors and methods should be invoked only on the EDT.

    db
  • 3. Null pointer exception in jdk 1.7
    946388 Newbie
    Currently Being Moderated
    Without seeing your code, any answers will be guesses.

    please upload your code as well.
  • 4. Re: Null pointer exception in jdk 1.7
    953423 Newbie
    Currently Being Moderated
    I can not put my code due to some constrain., But i would like to know is there any change in code ,that is causing key pressed is not recognized in jdk 1.7. I see this issue not frequently. Pls help me.
  • 5. Re: Null pointer exception in jdk 1.7
    sabre150 Expert
    Currently Being Moderated
    950420 wrote:
    Pls help me.
    Did you actually read Darryl's response?
  • 6. Re: Null pointer exception in jdk 1.7
    953423 Newbie
    Currently Being Moderated
    " All Swing constructors and methods should be invoked only on the EDT. ". Is this rule was included in Jdk7 or was existing in previous jdks also.? I am using EDT in my code. One more question i have , is there any change in EDT code in jdk7 such that it will affect any change in response time .

    Edited by: 950420 on Sep 10, 2012 2:08 AM

    Edited by: 950420 on Sep 10, 2012 2:42 AM
  • 7. Re: Null pointer exception in jdk 1.7
    jduprez Pro
    Currently Being Moderated
    " All Swing constructors and methods should be invoked only on the EDT. ". Is this rule was included in Jdk7 or was existing in previous jdks also.?
    All JDKs since Swing was included (1.2 IIRC). See the tutorial chapter http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html (a must-read, must-know, and must-apply).
    I am using EDT in my code.
    What does that mean? You previous questions suggests that you didn't know this rule.
  • 8. Re: Null pointer exception in jdk 1.7
    DarrylBurke Guru Moderator
    Currently Being Moderated
    950420 wrote:
    Is this rule was included in Jdk7 or was existing in previous jdks also.?
    Swing was always single threaded. Some of the methods that were documented to be thread safe up to JDK 6 were in fact never thread safe, and the qualification has been removed in the JDK7 documentation.
    is there any change in EDT code in jdk7 such that it will affect any change in response time .
    Huh?

    db
  • 9. Re: Null pointer exception in jdk 1.7
    953423 Newbie
    Currently Being Moderated
    thanks for the information. I see Bug ID: 6189501 , also had similar issue , but it was for menubar . Does button.requestFocus() works in jdk7??

    Edited by: 950420 on Sep 12, 2012 3:08 AM
  • 10. Re: Null pointer exception in jdk 1.7
    953423 Newbie
    Currently Being Moderated
    Hi I got the error point : getRootPane().setDefaultButton(btn);

    from here error starts. any idea anything wrong in this line

    Edited by: 950420 on Sep 12, 2012 5:53 AM
  • 11. Re: Null pointer exception in jdk 1.7
    953423 Newbie
    Currently Being Moderated
    I also see some time below error also:

    java.lang.Exception: Stack trace
         at java.lang.Thread.dumpStack(Thread.java:1342)
         at javax.swing.KeyboardManager.unregisterKeyStroke(KeyboardManager.java:171)
         at javax.swing.JComponent.unregisterWithKeyboardManager(JComponent.java:2202)
         at javax.swing.JComponent.registerWithKeyboardManager(JComponent.java:2140)
         at javax.swing.JComponent.componentInputMapChanged(JComponent.java:2193)
         at javax.swing.ComponentInputMap.clear(ComponentInputMap.java:115)
         at javax.swing.plaf.basic.BasicRootPaneUI.updateDefaultButtonBindings(BasicRootPaneUI.java:145)
         at javax.swing.plaf.basic.BasicRootPaneUI.propertyChange(BasicRootPaneUI.java:164)
         at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
         at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
         at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
         at java.awt.Component.firePropertyChange(Component.java:8382)
         at javax.swing.JRootPane.setDefaultButton(JRootPane.java:802)
         at javax.swing.plaf.basic.BasicButtonListener.focusLost(BasicButtonListener.java:192)
         at java.awt.Component.processFocusEvent(Component.java:6397)
         at java.awt.Component.processEvent(Component.java:6261)
         at java.awt.Container.processEvent(Container.java:2229)
         at java.awt.Component.dispatchEventImpl(Component.java:4861)
         at java.awt.Container.dispatchEventImpl(Container.java:2287)
         at java.awt.Component.dispatchEvent(Component.java:4687)
         at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1908)
         at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:937)
         at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:611)
         at java.awt.Component.dispatchEventImpl(Component.java:4731)
         at java.awt.Container.dispatchEventImpl(Container.java:2287)
         at java.awt.Component.dispatchEvent(Component.java:4687)
         at sun.awt.SunToolkit$4.run(SunToolkit.java:588)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
         at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
         at java.awt.EventQueue.access$000(EventQueue.java:101)
         at java.awt.EventQueue$3.run(EventQueue.java:666)
         at java.awt.EventQueue$3.run(EventQueue.java:664)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
         at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
  • 12. Re: Null pointer exception in jdk 1.7
    jduprez Pro
    Currently Being Moderated
    Hard to help you further, when there are one or two questions you've been asked above, which you have not answered.
    For better help sooner, I recommend you post an SSCCE (http://sscce.org)
  • 13. Re: Null pointer exception in jdk 1.7
    953423 Newbie
    Currently Being Moderated
    I was using EDT. May be i was not 100% sure about the usage of it. as i posted the error place , even that wont help ?
  • 14. Re: Null pointer exception in jdk 1.7
    jduprez Pro
    Currently Being Moderated
    Hello again,
    950420 wrote:
    I was using EDT. May be i was not 100% sure about the usage of it.
    As you have been told already (twice), the meaning of this sentence is very ambiguous.
    To understand why you should read this chapter of the Swing tutorial (but it's a bit involved): http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html
    as i posted the error place , even that wont help ?
    As you have been already told (twice)... no :)

    Your best chance to get further help is, as you have already been told (twice), to provide an SSCCE (http://sscce.org).

    The good thing with an SSCCE, is that it will help you isolate the problem to where it really belongs (there is probably only a small part of the code is really involved in the error, and a lot of incidental code that has nothing to do with the error). From there two possibilities:
    - you may be able to find out yourself (very self-rewarding, and it will teach you a lot). If you do please post about it anyway, as a courtesy to those who tried to help you.
    - you don't find yourself, but you can post the (short but complete) code here for other to reproduce and analyze it.

    Either way, if solving the problem is important to you, the effort will pay.
    If solving the problem is not that important, then drop the effort - but inform us here, as a courtesy to those who tried to help you.

    Best regards,

    J.

    Edited by: jduprez on Sep 21, 2012 11:59 AM

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points