File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main" java.lang.NullPointerException" Watch "Exception in thread "main" java.lang.NullPointerException" New topic

Exception in thread "main" java.lang.NullPointerException

Deepak Vishwakarma

Joined: Aug 19, 2012
Posts: 4
[Added code tags - see UseCodeTags for details]

i am not able to find the exception why occur
Matthew Brown

Joined: Apr 06, 2010
Posts: 4543

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.
Ankit Chaudhary

Joined: Sep 16, 2011
Posts: 3
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,
-------------------------------------------------------------------------------- --------------------------
AnkitChaudhary | |
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924

Date myDate = new Date();
BetterPerson myPerson = new BetterPerson("Deepak","Vishwakarna",myDate );

to use this he needs to have 3-arg constructor also that takes the third parameter of the type Date.
I agree. Here's the link:
subject: Exception in thread "main" java.lang.NullPointerException
It's not a secret anymore!