Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

static field should be accessed in a static way

208 views
Skip to first unread message

ireallynee...@yahoo.com

unread,
Apr 15, 2008, 9:00:32 PM4/15/08
to
Hi
I need to get the current time + 15 minutes for a given time zone.

Question: the c.get(...) show warnings such as
"The static field Calendar.HOUR_OF_DAY should be accessed in a static
way"

how do I avoid these warnings? thanks

public String addMinutes(String tz)
{
if (tz.equalsIgnoreCase("E"))tz="US/Eastern";
else if (tz.equalsIgnoreCase("C")) tz="US/Central";
else if (tz.equalsIgnoreCase("M")) tz="US/Mountain";
else if (tz.equalsIgnoreCase("P")) tz="US/Pacific";
else if (tz.equalsIgnoreCase("A")) tz="US/Alaska";
else if (tz.equalsIgnoreCase("H")) tz="US/Hawaii";
DecimalFormat f=new DecimalFormat("00");
Calendar c = Calendar.getInstance(TimeZone.getTimeZone(tz));
c.set
(
Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.YEAR),
Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.MONTH)
+1 ,

Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.DAY_OF_MONTH),

Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.HOUR_OF_DAY),
Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.MINUTE)
);
c.add(Calendar.MINUTE,15 );
// warnings appear below.....
String t=f.format(c.get(c.YEAR)) +
f.format(c.get(c.MONTH)) +
f.format(c.get(c.DAY_OF_MONTH)) +
f.format(c.get(c.HOUR_OF_DAY)) +
f.format(c.MINUTE);
return t;
}

Chase Preuninger

unread,
Apr 15, 2008, 9:08:19 PM4/15/08
to
then ccess it in a static way.

//non-static
MyObject o = new MyObject(...);
o.somethingStatic;

//proper static way
MyObject.somethingStatic;

Roedy Green

unread,
Apr 15, 2008, 11:18:09 PM4/15/08
to
On Tue, 15 Apr 2008 18:00:32 -0700 (PDT),
ireallynee...@yahoo.com wrote, quoted or indirectly quoted
someone who said :

>"The static field Calendar.HOUR_OF_DAY should be accessed in a static
>way"

see http://mindprod.com/jgloss/compileerrormessages.html#STATICFIELD
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Hendrik Maryns

unread,
Apr 16, 2008, 5:34:42 AM4/16/08
to
ireallynee...@yahoo.com schreef:

> Hi
> I need to get the current time + 15 minutes for a given time zone.
>
> Question: the c.get(...) show warnings such as
> "The static field Calendar.HOUR_OF_DAY should be accessed in a static
> way"

It’s not c.get() which is the problem, but that which is inside of it.
In the lines above, you do it right: c.get(Calendar.YEAR)

> Calendar.getInstance(TimeZone.getTimeZone(tz)).get(Calendar.YEAR),
Good.
> String t=f.format(c.get(c.YEAR)) +
Bad.

HTH, H.
--
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html

signature.asc
0 new messages