Results 1 to 4 of 4
  1. #1
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default cannot call private method from static method

    Any idea how to resolve this?
    :eek:

    import java.util.*;
    public class DateLib {

    private final long DAYS_TO_HOURS = 24L;
    private final long HOURS_TO_MINUTES = 60L;
    private final long MINUTES_TO_SECONDS = 60L;
    private final long SECONDS_TO_MILLISECONDS = 1000L;

    public static long getMillisecondsFromEpoch (int aYear, int aMonth, int aDay) {
    /*
    * Epoch is January 1, 1970 00:00.00 000 GMT
    */
    //TODO calculate no of Years to milliseconds
    final long Year = (((long) aYear) - 1970L);

    if (!(isLeapYear)) {
    // ERROR: Exception in thread "main" java.lang.Error: Unresolved compilation //problem: isLeapYear cannot be resolved

    }
    else {

    }

    return Year;
    }

    public static long getMillisecondsFromEpoch (int aYear, int aMonth, int aDay,
    int aHour, int aMinute, int aSecond)
    {
    /* TODO **
    * Epoch is January 1, 1970 00:00.00 000 GMT
    */
    return 0L;

    }

    private boolean isLeapYear (int aYear) {
    /*
    * if year modulo 400 is 0 then leap
    * else if year modulo 100 is 0 then no_leap
    * else if year modulo 4 is 0 then leap
    * else no_leap
    * (Source: Leap year - Wikipedia, the free encyclopedia)
    */

    if ((aYear % 400) == 0) {return true;}
    else if ((aYear % 100) == 0) {return false;}
    else if ((aYear % 4) == 0) {return true;}
    else {return false;}
    }

    }

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Quote Originally Posted by jon80 View Post
    Any idea how to resolve this?
    :eek:

    import java.util.*;
    public class DateLib {

    private final long DAYS_TO_HOURS = 24L;
    private final long HOURS_TO_MINUTES = 60L;
    private final long MINUTES_TO_SECONDS = 60L;
    private final long SECONDS_TO_MILLISECONDS = 1000L;

    public static long getMillisecondsFromEpoch (int aYear, int aMonth, int aDay) {
    /*
    * Epoch is January 1, 1970 00:00.00 000 GMT
    */
    //TODO calculate no of Years to milliseconds
    final long Year = (((long) aYear) - 1970L);

    if (!(isLeapYear)) { // HERE YOU ARE NOT CALLING THE METHOD
    // ERROR: Exception in thread "main" java.lang.Error: Unresolved compilation //problem: isLeapYear cannot be resolved

    }
    else {

    }

    return Year;
    }

    public static long getMillisecondsFromEpoch (int aYear, int aMonth, int aDay,
    int aHour, int aMinute, int aSecond)
    {
    /* TODO **
    * Epoch is January 1, 1970 00:00.00 000 GMT
    */
    return 0L;

    }

    private boolean isLeapYear (int aYear) {
    /*
    * if year modulo 400 is 0 then leap
    * else if year modulo 100 is 0 then no_leap
    * else if year modulo 4 is 0 then leap
    * else no_leap
    * (Source: Leap year - Wikipedia, the free encyclopedia)
    */

    if ((aYear % 400) == 0) {return true;}
    else if ((aYear % 100) == 0) {return false;}
    else if ((aYear % 4) == 0) {return true;}
    else {return false;}
    }

    }
    see your code again and analyze it.

    Where you defined the isLeapYear variable.....

    and mark the isLeapYear method as static if you want to call it from static method
    sanjeev,संजीव

  3. #3
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    I did but no joy yet

  4. #4
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Quote Originally Posted by jon80 View Post
    I did but no joy yet
    post the code here that you did....
    sanjeev,संजीव

Similar Threads

  1. Non-Static method in static context error
    By wizmang in forum New To Java
    Replies: 4
    Last Post: 04-24-2008, 08:51 AM
  2. Call a Method Automatically
    By rhm54 in forum New To Java
    Replies: 4
    Last Post: 02-07-2008, 08:51 AM
  3. Private main method
    By bugger in forum New To Java
    Replies: 1
    Last Post: 12-21-2007, 09:45 AM
  4. Unablt to call a sessionbean's business method in EJB 3.0
    By amitid4forum in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 11-24-2007, 12:00 PM
  5. Replies: 1
    Last Post: 08-07-2007, 05:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •