Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

DateFormat class - not getting result  RSS feed

 
sasikumar palakkizhi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When I compiled the below code which uses DateFormat,I got an run time Exception in the line df.format(now) showing an IllegalArgumentException - can not format given Object as a date. When I looked the API,format() method accepts a Date object. What will be the reason for this exception?



Thanks in advance
sasi
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your own class is also called Date. Instead of java.util.Date, it is using your own class. That won't work.

Rename your class to something else than "Date".
 
Nigel Browne
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although it is very bad practice to name your classes to the same name as a class from the Java API you could solve your issue my specifing which Date class to use.


This is NOT recommended though and I would suggest renaming your class to MyDate instead.
[ June 28, 2006: Message edited by: Nigel Browne ]
 
sasikumar palakkizhi
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies.. It is working fine

regards
sasikumar
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!