aspose file tools*
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
Author

Exception in thread "main" java.lang.NullPointerException

Deepak Vishwakarma
Greenhorn

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
Bartender

Joined: Apr 06, 2010
Posts: 4240
    
    7

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
Greenhorn

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,
Ankit
-------------------------------------------------------------------------------- --------------------------
AnkitChaudhary | ankchaudhary@infocepts.com | www.infocepts.com
--------------------------------------------------------------
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 923
    
    1

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.


OCPJP 6(100 %) OCEWCD 6(91 %) OCPJBCD(93%)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" java.lang.NullPointerException
 
Similar Threads
need help plss
comparing two objects by overriding equals and hashCode
private constructor
please explain with an example
JSF action doesn't call bean method