• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Vinu Menon
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one tell me why i am getting null pointer exception in the below program




Thanks
Vinay.
 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stephen Davies
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, check your references.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic