aspose file tools*
The moose likes Beginning Java and the fly likes null pointer exception problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "null pointer exception problem" Watch "null pointer exception problem" New topic
Author

null pointer exception problem

Frances Hollis
Greenhorn

Joined: Sep 02, 2006
Posts: 17
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

Joined: Sep 11, 2006
Posts: 959

It's because you never initialize the outer object (JPanel).


SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
jQuery in Action, 2nd edition
 
subject: null pointer exception problem