• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Exception in thread "main" java.lang.NullPointerException

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Added code tags - see UseCodeTags for details]

i am not able to find the exception why occur
 
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The exception message will tell you on exactly which line it occurs. That will help you work it out, but if it's not enough you should tell us which line, as it makes it much easier for us to help you.

However, I think I see the problem. Look at line 13. Was dob supposed to be a parameter passed in to the constructor? Because at the moment you're trying to initialise the instance variable dob with itself. So the reference you're trying to call getTime() on is null.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Deepak,


Date is not passed as parameter to the constructor,this is causing NPE .



I think here you declared the myDate but its not passed as parameter.You can make the change as below.


Let me know if this is helpful.


Thanks and Best Regards,
Ankit
-------------------------------------------------------------------------------- --------------------------
AnkitChaudhary | ankchaudhary@infocepts.com | www.infocepts.com
--------------------------------------------------------------
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Date myDate = new Date();
BetterPerson myPerson = new BetterPerson("Deepak","Vishwakarna",myDate );
System.out.println(myPerson.getDOB());




to use this he needs to have 3-arg constructor also that takes the third parameter of the type Date.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic