• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JLayeredPane is giving a NullPointerException

 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Main Frame which on top of sits a Main Panel. Its on top of this panel that all other panels are being created and added. I want to use a JLayeredPane to pop up a notify box of events that happen within the app. Using this code in that Main Panel...



then when I run the app I receive this error...

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at gui.MainPanel.<init>(MainPanel.java:47)
at gui.MainFrame.createComponents(MainFrame.java:38)

Where line 47 is the first call to JLayeredPane...

Any ideas?
 
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, it does not seem like JLayeredPane is giving a NullPointerException. According to the information specified by you it looks like JLayeredPane == null. Hence the first call on it will cause a nullpointer to be fired!

Maybe you should check how you are acquiring this and see in the javadocs how it should be acquired!
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume you are familiar with the different ways of chasing null values. That topic comes up regularly in the Java in General fora.

If you look up the getRootPane methods in the API documentation, you find some of them may return null. It is worthwhile taking that chained invocation apart into component lines each with only one . operator in, then in the next line put a print statement to see whether you have got a null value. It might be worth trying this.getRootPane() rather than super.getRootPane().
 
Chris Dancy
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To answer the first post... How can JLayeredPane == null if im getting the JLayeredPane from a panel? And to answer the second post, I originally had this instead of super and it was giving the same problem. I switched to super to see if it made a difference but alas, none was made.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic