Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-07-2008, 09:16 AM
Member
 
Join Date: Feb 2008
Posts: 23
jon80 is on a distinguished road
cannot call private method from static method
Any idea how to resolve this?


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;}
}

}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-07-2008, 09:24 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
Quote:
Originally Posted by jon80 View Post
Any idea how to resolve this?


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,संजीव
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-07-2008, 09:30 AM
Member
 
Join Date: Feb 2008
Posts: 23
jon80 is on a distinguished road
I did but no joy yet
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-07-2008, 09:37 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
Quote:
Originally Posted by jon80 View Post
I did but no joy yet
post the code here that you did....
__________________
sanjeev,संजीव
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Non-Static method in static context error wizmang New To Java 4 04-24-2008 09:51 AM
Call a Method Automatically rhm54 New To Java 4 02-07-2008 09:51 AM
Private main method bugger New To Java 1 12-21-2007 10:45 AM
Unablt to call a sessionbean's business method in EJB 3.0 amitid4forum Enterprise JavaBeans 0 11-24-2007 01:00 PM
Error: Non-static method append(char) cannot be referenced from a static context paul Advanced Java 1 08-07-2007 06:05 AM


All times are GMT +3. The time now is 06:26 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org