• Post Reply Bookmark Topic Watch Topic
  • New Topic

JLayeredPane is giving a NullPointerException  RSS feed

 
Chris Dancy
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • 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?
 
Manuel Moons
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • 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!
 
Campbell Ritchie
Sheriff
Posts: 53774
128
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!