This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

null pointer exception problem  RSS feed

 
Frances Hollis
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting a null pointer exception and I don't know why. Here is the error message.

Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1015)
at java.awt.Container.add(Container.java:351)
at EditorFrame.<init>(NewEditor.java:23)
at NewEditor.main(NewEditor.java:9)
Press any key to continue . . .



Here is the code. I would appreciate any suggestions.

 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's because you never initialize the outer object (JPanel).
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Frances Hollis:
I am getting a null pointer exception and I don't know why. Here is the error message.

Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1015)
at java.awt.Container.add(Container.java:351)
at EditorFrame.<init>(NewEditor.java:23)
at NewEditor.main(NewEditor.java:9)...]

Note that the error message provides the line numbers tracing where the error occurs.

In line 9, you are calling an EditorFrame constructor. In that constructor, at line 23, you are calling contentPane.add(outer); but "outer" is still null. That is the problem with your code.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!