f



static field should be accessed in a static way

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;
	}
0
4/16/2008 1:00:32 AM
comp.lang.java.programmer 52714 articles. 1 followers. Post Follow

3 Replies
4319 Views

Similar Articles

[PageSpeed] 4

then ccess it in a static way.

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

//proper static way
MyObject.somethingStatic;
0
4/16/2008 1:08:19 AM
On Tue, 15 Apr 2008 18:00:32 -0700 (PDT),
ireallyneedtoknow2007@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
0
see_website (5876)
4/16/2008 3:18:09 AM
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig15207CBA3ADBFEB9406D828C
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

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

It=E2=80=99s not c.get() which is the problem, but that which is inside o=
f it.=20
In the lines above, you do it right: c.get(Calendar.YEAR)

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

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


--------------enig15207CBA3ADBFEB9406D828C
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFIBcg4e+7xMGD3itQRApHAAJ9WBuEpu2gKsyeUSDmJiNihLtfPPACfaoHk
Rgx6o+98H79Tl2DSvMBJYPg=
=KWfK
-----END PGP SIGNATURE-----

--------------enig15207CBA3ADBFEB9406D828C--
0
gtw37bn02 (240)
4/16/2008 9:34:42 AM
Reply:

Similar Artilces:

To static or not to static
If I have a class such as:------------------public class MyClass{ public MyClass() { super(); } public void printThis(String parm) { System.out.println(parm); }}------------------I can run the method like this:(new MyClass()).printThis("Hello World");Since printThis only uses passed parameters, I could also have this:------------------public class MyClass{ public MyClass() { super(); } public static void printThis(String parm) { System.out.println(parm); }}------------------and then I can run the method like this:MyClass.printThis("Hello World");Bo...

java question about static variable in static method
HI, I have a simple program which does not compile:public class class1{public static void main(String[] args){ static int i=0;//static is not allowed, why?}}Can you tell me why this is not allowed?ThanksAakash Aakash wrote:> HI, I have a simple program which does not compile:> public class class1{> > public static void main(String[] args)> {> static int i=0;//static is not allowed, why?> }> > }> > Can you tell me why this is not allowed?> Thanks> AakashStatic variables may only be class variables. There is some discussion about 'closures', which...

How can I access non-static variables from static funcition?
Is it possible ? There is any work around? Thanx Neviton wrote: > Is it possible ? > > There is any work around? > > Thanx > If you need to modify an instance, pass in an reference or pointer to the object, if you just want to call the function, then create a temp obj (const/non-const). Last resort, there must be something wrong with your design, refactor. -- Thanks Barry Thanks for the quickly response Barry. > Last resort, there must be something wrong with your design, refactor. Yes probably. :) I'm starting. Perhaps you can give me some tip. I'm...

static or non static
this is probably only a stylistic question what do you think to be better in a single .c file program, declaring functions with static qualifier or without it? eg: #include <stdio.c> static int add(int a, int b) {return a+b;} int main() { printf("1+2=%d\n", add(1, 2)); return 0; } is there any difference between the two? static int add(..) or int add(..) Szabolcs Nagy wrote: > this is probably only a stylistic question > > what do you think to be better in a single .c file program, declaring > functions with static qualifier or without it? > > ...

static and non static
i am trying to implement interface, and static method cannot be called in non static method. So my one class is public static void main and other is non-static. Test file ----------------- public class Test { public static void main(String args[]) { byte [] encoded =Round.doOneRound(data,key); } Round ----------- public interface Round { public byte[/*8*/] doOneRound( byte[/*8*/] data, byte[/*6*/] key ); /*public byte[/*8*/] doOneRound( byte[/*8*/] data, byte[/*6*/] key ) So the error i m getting is non static method doOneRound cannot be referrenced from a sta...

Can a static member function access non-static member?
Hello everyone! Can a static member function access non-static member? I think it is illegal.Is it right? On Dec 5, 9:27 am, dolphin <jdxyw2...@gmail.com> wrote: > Hello everyone! Can a static member function access non-static member? > I think it is illegal.Is it right? Write a 10-line test program and see :) dolphin wrote: > Hello everyone! Can a static member function access non-static member? > I think it is illegal.Is it right? Yes, provided it has a pointer or reference to the object. Why shouldn't it? -- Ian Collins. On 2007-12-05 02:27:21 -0500, dolphin &l...

Why inner class can not have static data, static fields or nested class?
Quote from <Thinking in Java>, chapter 8:"Fields and methods in ordinary inner classes can only be at the outerlevel of a class, so ordinary inner classes cannot have static data,static fields, or nested classes."Will anybody tell me what means "at outer level of a class"? Thanksvery much!...

Static fields accessed by getter/setter...what happens?
(apology for duplicate post, I felt I posted in the wrong forum earlier.) Could someone please enlighten me as to what will happen if I have: public class MyClass { public static String someName = null; public void setSomeName(String s) { someName = s; } public void getSomeString() { return someString; } } I'm not sure how the static field is being handle using non-static getters/setters. Thanks Stacey Well, the first response should be, "what happened when you tried it?". Past that, your class instances do have access to static v...

Static vs Non static
Dear all, Today I was part of a fruitful discussion. But that left me in mere oblivion. A static method cannot access non static members of the class. Well, thats fine and clear. But a non static method ( or instance method) can access a static variable in Java!!! But a non static method is basically doing an instance service. Hence how come instance service be allowed to manipulate a class variable ( or static variable ) ? Surely C++ throws an exception, and is that not a drawback in Java language syntax? Or anyone please suggest a situation where instance service has to manipulate a class variable ? Constructor makes sense, and let constructors be the only functions which has the power to do both instance and class service. But other than constructors, every other instance method should be disallowed to use a class variable, right? Please share your comments, thanks. Just for the discussion and value added remarks, I am keeping the post to comp.lang.java as well. Regards, Ravi Ravi Shankar:-) Although I think the discussion for the most part is more like an academic one, I can tell you that In smalltalk dialects I know objects can access their class his variables. It also seems natural to me to have that kind of relation. Lets create an anology in real life: a table surely might access everything that is related to being a table, also for instance its "class name". I am pretty sure c++ allows that too! type_name or something like that I ...

static var and static map
Hi I have a method with some static double variables, if I make a map<string,double> instead, will it do the same thing? apart from assigning and accessing the values. thank you Gary Wessle <phddas@yahoo.com> writes: >> Hi > > I have a method with some static double variables, if I make a > map<string,double> instead, will it do the same thing? apart from > assigning and accessing the values. > > thank you do I need to make the values themselves static or no need. i.e static map<string,int> m; static int a = 5; m["a"] = 5; or ju...

Static Versus Non Static
Dear all, Today I was part of a fruitful discussion. But that left me in mere oblivion. A static method cannot access non static members of the class. Well, thats fine and clear. But a non static method ( or instance method) can access a static variable in Java!!! But a non static method is basically doing an instance service. Hence how come instance service be allowed to manipulate a class variable ( or static variable ) ? Surely C++ throws an exception, and is that not a drawback in Java language syntax? Or anyone please suggest a situation where instance service has to manipula...

static and non-static functions
What is the difference between those two. Is there gonna be some difference in app execution for static functions? What difference does it make? UF Ufit wrote: > What is the difference between those two. Is there gonna > be some difference in app execution for static functions? > What difference does it make? Static functions do not require (nor do they have, internally) an instance of the class to be called. Non-static, vice versa, do require and provide (through 'this' pointer) an instance of the class for which they are called. I am not sure how to answer the second qu...

static
What I can compile my program to static version? Now I use g++ -Wall -I./include -o program `wx-config --cxxflags --libs` ../obj/module1.o ./obj/modula2.o when I add --static=yes I get many errors add to the wx-config: --static=yes On 12/3/07, Zorro <zorro@zoooooro.pl> wrote: > > What I can compile my program to static version? > > Now I use > g++ -Wall -I./include -o program `wx-config --cxxflags --libs` > ./obj/module1.o ./obj/modula2.o > > when I add --static=yes I get many errors > > > > --------------------------------...

static
Hi, This should print 1 2 end but it prints only 1 Why? Jean Pierre Daviau -- http://www.JeanPierreDaviau.com ==== public class Doc { static int i=0; public static void main(String [] args) { Doc.i++; System.out.println (i); new Doc1(); System.out.println ("end"); } } class Doc1 { public static void main(String [] args) { Doc.i =Doc.i + 2; System.out.println (Doc.i); } } On Thu, 15 Jul 2004 11:48:21 -0400, "Qu�bec" <Once@WasEno.ugh> wrote: >Hi, > >This should print >1 >2 >end > >but it prints only >1 public class Doc { static int i=0; public static void main(String [] args) { Doc.i++; System.out.println (i); new Doc1(); System.out.println ("end"); } } class Doc1 { public static void main(String [] args) { Doc.i =Doc.i + 2; System.out.println (Doc.i); } } Why do you think it should? Here's what it doest: 1. Increment Doc.i. i is now 1. 2. Print i to system out. 3. Create new instance of class Doc1. Since there is no default constructor, it just creates an instance. 4. Print the string "end" to output. I suspect you think the public static void main function is going to execute. It won't. Not unless you call it explicitly like this: public class Doc { static int i = 0; public static void main(String[] args) { Doc.i++ System.out.println(i); Doc...

static
hello guys plz tel me the differances between global static and local static. If possible with examples vim wrote: > hello guys > > > > plz tel me the differances between global static and local static. > If possible with examples Please explain what you mean by "global static" and "local static," because the Standard that defines the C language does not use either phrase. -- Eric Sosman esosman@acm-dot-org.invalid On Mar 22, 8:34 pm, Eric Sosman <esos...@acm-dot-org.invalid> wrote: > vim wrote: > > hello guys > > >...

static
In a book the author said:"If you have a member function that accesses only the static data members of a class, you can declare the function static as well." I don't understand that what's the advantages of making a member static since static member functions can access non-static data in a class no matter what. Could someone explain on this? Thanks! Hi, "stub" <stub@asof.com> wrote in message news:E%Spb.27152$Ec1.2487442@bgtnsc05-news.ops.worldnet.att.net... > In a book the author said:"If you have a member function that accesses only > the...

Static
Hi I hope there's someone here who can help me with this because I've never seen the like of it. It's a PIC16C58B driving an LCD in a small, hand held ABS plastic case. There's a reverse printed perspex/lucite display cover held on with pressure sensitive adhesive. Inside it's all cmos to conserve power. If you stroke the display cover with your finger you get spurious readings, someone just called to report the problem and I don't know how to fix it. There is nothing to ground it to, it runs of internal batteries, why should it care about static??? He...

Static variable & static method
Hello, I have the following code and I still don't know why it prints "10 10" instead of "5 10". #include <iostream> using namespace std; class A { static int i; public: static int get_i() { return i; } static int dbl() { i = i * 2; return i; } }; int A::i = 5; int main() { cout << A::get_i() << " " << A::dbl() << endl; return 0; } Can anyone help me understand this? Thank you, Stefan Istrate On 2008-06-06 12:20, Stefan Istrate wrote: > He...

static object and static function in c++
who can tell me about static object and static function's implement detail with C++ compiler? some books said: static object just have only ONE object but i dont think so. for ex: a.h class A { // some details }; static A& inst() { static A a; return a; } a.cpp #include "a.h" void A::func() { inst().variable = 100; } xxx.cpp #include "a.h" int main() { inst().func(); cout << inst().variable <<endl; // 0 } we dont argument about: static func must be implement in cpp file. i think the compiler make a copy of the static func( or object ) in ...

static call of non-static method?
Hi i was wondering why i can call a class method, by double colon. without declaring it static. this is my test class Test_1 { public function hello() { echo 'Hello'; } } Test_1::hello(); On 21.09.2007 14:49 Mads Lee Jensen wrote: > Hi i was wondering why i can call a class method, by double colon. > without declaring it static. > > this is my test > > class Test_1 > { > public function hello() > { > echo 'Hello'; > } > } > Test_1::hello(); > This behaviour is for compatibility with php4. It raises a ...

initialising static member with static methode
Hi, I have some kind of tricky question on the c++ internals. There must be some rule in what order static members get initialised. I need to initialise a static member (m_sPropertyInfos) using a static methode (initStaticPropertyInfos). This static methode uses a static member staticMetaObject of the superclass. Will that work with all compilers (it is fine with gcc-4.x) myfile.cpp: /*static*/ QList<AXPropertyInfo*> AXData::initStaticPropertyInfos() { QList<AXPropertyInfo*> propertyInfos; for(int i=0; i<staticMetaObject.propertyCount(); i++) { propertyInfos.append(0)...

non-static variable in a static context
I'm trying to compile a program which compares different types of sorts. I have different classes containing each sort. when I try to create the objects to do the sorting in the main method, it gives me an error that says "non-static variable this cannot be referenced from a static context." for each object declaration. Does anyone know how I can fix this, or what I'm doing wrong, because I've been stuck for days. here is my code: import java.io.*; import java.lang.String; class Sorting { public static void main (String[]args) throws IOException { AnyType line; // StringBuffer contents = new StringBuffer(); AnyType[] arr = new AnyType[2000]; String infile = "sortfile.txt"; FileReader fr = new FileReader(infile); BufferedReader inFile = new BufferedReader(fr); while((line = inFile.readLine()) != null) // contents.append(line); for(int i = 0; i < arr.length; i++) { arr[i] = line; } BubbleSort bs = new BubbleSort(); SelectionSort ss = new SelectionSort(); InsertionSort is = new InsertionSort(); bs.bubbleSort(arr); ss.selectionSort(arr); is.insertionSort(arr); } interface AnyType { public boolean isBetterThan(AnyType data); } abstract class IntegerType implements AnyType { private int number; IntegerType() { number = 0; } ...

non-static method...static context
Hi this code is for a subtitle pane in our GUI. when we try to call Subtitle.setSubtitleText("whatever"); from another class we get this error: Game2.java:198: non-static method setSubtitleText(java.lang.String) cannot be re ferenced from a static context Subtitle.setSubtitleText("Woohoo!"); ^ 1 error Does anyone know what the problem is? Thanks Leo code: import javax.swing.*; public class Subtitle extends JPanel { // Set up the components in the frame. public Subtitle(int gameNumber, String text){ super(); set...

static vs non-static variables
Hello all, I am still kind of confused with static vs non-static fields. I understand that the static keyword is associated with the class, and not the object. But, for example, if you have non static fields, doesn't each object instatiated from this class contain those fields, or is it just when you use the word static; that each object contains those fields. I know objects have state(which are represented by fields) and behavior ( which are their methods). But still uncertain about static vs non static fields. If anyone could please help me understand the difference that would be great, and much appreciated. Thanks again In article <Pz8bf.420224$tl2.373148@pd7tw3no>, Michael <mbialowas@shaw.ca> wrote: >Hello all, I am still kind of confused with static vs non-static fields. I >understand that the static keyword is associated with the class, and not the >object. But, for example, if you have non static fields, doesn't each object >instatiated from this class contain those fields, Right. >or is it just when you use >the word static; that each object contains those fields. Wrong. Each object has its own copy of the non-static fields. For static fields, there's one copy, which is shared by all instances of the class (and other objects, assuming it's not private). In fact, the static fields are created when the class is loaded (AFAIK), so they exist whether there are any instances of the class or not. One sit...

Web resources about - static field should be accessed in a static way - comp.lang.java.programmer

INFOGRAPHIC: Information Accessed By Facebook-Connected Apps
According to application security provider MyPermissions , more than 70 billion mobile apps will be downloaded in 2013, or 10 for every person ...

Facebook launches new APIs to make it easier for real-time activity to be accessed
Many media organizations are catching on, wanting to know what people on Facebook are saying about a certain topic . While it’s easier with Twitter, ...

IRGC commander tell how the US RQ 170 Drone was captured and its content & technology accessed - YouTube ...
The commander of Revolutionary Guard aerospace Sardar Hajizadeh tell how the US RQ 170 was captured and how the Revolutionary Guard succeeded ...

Australia Post data shows more mail being accessed by government agencies
Australia Post disclosed confidential information to law enforcement, security and other government agencies more than 10,000 times in 2013-14, ...

Aurora hackers said to have accessed law enforcement targets - U.S. Department of Justice, applications ...
Chinese cyber marauders sought more than just information on activists they wanted access to FBI, DOJ investigations on spies in the U.S.

AFP spied on phone and internet records, over 40,000 accessed without warrant
AUSTRALIAN Federal Police accessed more than 40,000 phone and computer records last year without a warrant.

Fairfax Media journalist Natalie O'Brien: Vodafone employee accessed my text messages
It is a creepy, nauseating experience knowing someone has been looking through your messages.

No jail for police detective who accessed child porn
A Victorian police detective who accessed child pornography to escape from the stresses of work has been spared jail.

David Jones says third party accessed 'limited' customer information
David Jones has suffered an online privacy breach, continuing a week of upheaval for the department store chain.

U.S. Netflix accessed by 1/3 of anglophone Canadian users
There's a not-so-secret trick for Canadian Netflix subscribers to access movies and TV shows that are supposed to be available only in the U.S. ...

Resources last updated: 3/15/2016 11:09:24 AM