472,373 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 software developers and data experts.

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 25096
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 ...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.