It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic


Vinu Menon

Joined: Jan 26, 2009
Posts: 20
Can any one tell me why i am getting null pointer exception in the below program

Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
because in your case the variable (a) is for the first instance. however when you do

new Thread(new B()).start()

a new object of type B will be created and its instance vaiable (a) is still null. so you either have to initialize your (a) variable in the constructor of class B, or do that line of code like this

Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Yup, check your references.

be a well encapsulated person, don't expose your privates, unless you public void getWife()!
I agree. Here's the link:
subject: Threads
It's not a secret anymore!