isLeapYear not working?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: isLeapYear not working?

  1. #1
    Join Date
    May 2004
    Posts
    4

    isLeapYear not working?

    I am trying to use the isLeapYear function in my program and it doesn't seem to be working. Here is a bit of code:

    Code:
    Calendar cal = new GregorianCalendar();
    boolean leap = cal.isLeapYear(2004);
    I am getting the following error when I try to compile it:

    Code:
    cannot resolve symbol method isLeapYear(int)
    All of my other calendar methods are working fine so I don't know what is going on. I am using java sdk 1.4.2_03. Any help would be greatly appreciated. Thanks.

  2. #2
    Join Date
    Jan 2004
    Posts
    22
    isLeapYear doesn't seem to be one of Calendar's methods. You should just be able to to something like "if (whateverThisYearIs-2000%4==0) isLeapYear=true;", I think .

  3. #3
    Join Date
    Feb 2004
    Posts
    541
    isLeapYear(int year) isn't one of Calendars methods, but is IS one of GregorianCalendars methods. The problem is that your object is of type Calendar, not GregorianCalendar. If you change it to type GregorianCalendar then it will work.

  4. #4
    Join Date
    Feb 2004
    Posts
    808
    Originally posted by mikeBarr81
    isLeapYear(int year) isn't one of Calendars methods, but is IS one of GregorianCalendars methods. The problem is that your object is of type Calendar, not GregorianCalendar. If you change it to type GregorianCalendar then it will work.
    well, kinda.. his object is actually of type GregorianCalendar thanks to "new GregorianCalendar", but it is wearing Calendar's clothes, and hence doesnt appear to have all the required pockets..

    mike's right by the way.. youre declaring a variable of type calendar, and then initializing it with a type GregorianCalendar. Though your object is of the right type internally, it is cast into and thought of (by java) as a normal Calendar object, which doesnt have isLeapYear()
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center