473,466 Members | 1,412 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Resolving a non-static cannot be referenced from a static context error

I'm trying to get the day of month with:

int dayofmonth;
dayofmonth = Calendar.get(Calendar.DAY_OF_MONTH);

and I get the compile time error of saying get(int) is a not-static method.

Is there a process (or a different class/method to call) that will work?

Thanks, John
Jul 17 '05 #1
3 25172
On Mon, 29 Sep 2003 12:57:45 -0700, John Bowling wrote:
I'm trying to get the day of month with:

int dayofmonth;
dayofmonth = Calendar.get(Calendar.DAY_OF_MONTH);

and I get the compile time error of saying get(int) is a not-static method.

Is there a process (or a different class/method to call) that will work?

Thanks, John

Hi John,

When get is not defined as static this means that you have to create a
GregorianCalendar object and call get on that; I guess this is because the
creators of the class wanted programmers to be able to give the calendar
their own layout.

Here is an example on how to set up a GregorianCalendar object (most is from Java's API):

String[] ids = TimeZone.getAvailableIDs(1 * 60 * 60 * 1000);
if (ids.length == 0)
System.exit(0);
SimpleTimeZone pdt = new SimpleTimeZone(1 * 60 * 60 * 1000, ids[0]);
pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
GregorianCalendar calendar = new GregorianCalendar(pdt);
calendar.setTime(new java.util.Date());

int dayofmonth = calendar.get(Calendar.DAY_OF_MONTH);

Best Regard
Kristian

Jul 17 '05 #2

"Kristian Bisgaard Lassen" <kr***@daimi.au.dk> wrote in message
news:pa****************************@daimi.au.dk...
On Mon, 29 Sep 2003 12:57:45 -0700, John Bowling wrote:
I'm trying to get the day of month with:

int dayofmonth;
dayofmonth = Calendar.get(Calendar.DAY_OF_MONTH);

and I get the compile time error of saying get(int) is a not-static method.
Is there a process (or a different class/method to call) that will work?

Thanks, John Hi John,

When get is not defined as static this means that you have to create a
GregorianCalendar object and call get on that; I guess this is because the
creators of the class wanted programmers to be able to give the calendar
their own layout.

Here is an example on how to set up a GregorianCalendar object (most is

from Java's API):
String[] ids = TimeZone.getAvailableIDs(1 * 60 * 60 * 1000);
if (ids.length == 0)
System.exit(0);
SimpleTimeZone pdt = new SimpleTimeZone(1 * 60 * 60 * 1000, ids[0]);
pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
GregorianCalendar calendar = new GregorianCalendar(pdt);
calendar.setTime(new java.util.Date());

int dayofmonth = calendar.get(Calendar.DAY_OF_MONTH);

Best Regard
Kristian


That solved it.
Thanks, John
Jul 17 '05 #3

"Kristian Bisgaard Lassen" <kr***@daimi.au.dk> wrote in message
news:pa****************************@daimi.au.dk...
On Mon, 29 Sep 2003 12:57:45 -0700, John Bowling wrote:
I'm trying to get the day of month with:

int dayofmonth;
dayofmonth = Calendar.get(Calendar.DAY_OF_MONTH);

and I get the compile time error of saying get(int) is a not-static method.
Is there a process (or a different class/method to call) that will work?
When get is not defined as static this means that you have to create a
GregorianCalendar object and call get on that; I guess this is because the
creators of the class wanted programmers to be able to give the calendar
their own layout.


(snip)

It can be done with the Calendar class. You can even create the object with
the same name, so that it works as asked.

import java.util.*;

class calendar {
static public void main(String args[]) {
Calendar Calendar=java.util.Calendar.getInstance();
System.out.println(Calendar.get(Calendar.DAY_OF_WE EK));
}

Some people will suggest giving the object reference variable a different
name, though.

-- glen
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Lorenzo Bolognini | last post by:
Hi all, I'm trying to build a sort of datagrid control by which i wish to edit/delete/update data in a table. Since I'm using foreign-keys for normalizing data in the db I need, when I add or...
0
by: Olav | last post by:
Resolving character references with C++/Arabica I have an element that looks like this: <PhoneNumber>&lt;NUMBER&gt;</PhoneNumber> I would like to have the content returned as "<NUMBER>". Not...
1
by: Vineeth | last post by:
Hi, I am using xerces2.6.0 and am developing a program for converting an xml document to a text file. My program is extending the DefaultHandler. The first problem I am facing is that even...
2
by: Gustaf Liljegren | last post by:
I need to merge several XML files into one large. All of them has a DOCTYPE tag, but the SYSTEM identifier points to a DTD that doesn't exist. (I use the PUBLIC identifier with catalog files, so...
27
by: Ken Human | last post by:
I want to generate every possible 16 character combination of the characters 0-9, A-Z, and a-z programatically. My current code follows: #include <stdio.h> #include <ctype.h> int main() {...
0
by: Wanderer | last post by:
Hi all, who knows how to correctly make assembly resolving in asp.net? In WinApplications AppDomain.CurrentDomain.AssemblyResolve event works fine, but this is not a case of asp.net. If I...
1
by: Stephen | last post by:
Hi all, is there a way that I can create an application that can "Resolve" any given address in the URL to be redirected to a default website. I guess that It can be done by "Resolving DNS...
0
by: DaveS | last post by:
I have a web service that returns one parameter which is defined as a string. In this string is returned an XML document (due to the fact that I have a large amount of data to pass back to the...
3
by: AK | last post by:
Hi Our product uses MS-SQL Server 2000. One of our customer has 10 installations with each installation stroring data in its own database. Now the customer wants to consolidate these databases...
8
by: junky_fellow | last post by:
Hi, Sorry, for asking similar questions again and again. 1) I want to know how should we reslove the ambiguities in a c expression ? Should we use precedence table as mentioned in K&R book ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.