Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Product and Other Certifications and the fly likes static problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "static problem." Watch "static problem." New topic

static problem.

Jim Crawford
Ranch Hand

Joined: Sep 08, 2002
Posts: 127
This code produces the following error.

Project settings saved
Building "Test1"
f:\Installed\WirelessToolkit2.1\apps\Test1\src\ non-static variable display cannot be referenced from a static context
1 error
Build failed

BUT on 'commenting in' the first /*static*/ as follows:
public /*static*/ Display display = null;
The code compiles.

How is that "POINT X" a static context?

<img src="cool.gif" border="0"> <img src="graemlins/beerchug.gif" border="0" alt="[beerchug]" /> <br />SCJP 1.4
Jim Crawford
Ranch Hand

Joined: Sep 08, 2002
Posts: 127
Any takers?
Michael Yuan
Ranch Hand

Joined: Mar 07, 2002
Posts: 1427
Well, you are referring to a member using the class name not the instance variable. So, the compiler has to assume that member is static. Right?

Seam Framework:
Jim Crawford
Ranch Hand

Joined: Sep 08, 2002
Posts: 127
Well... guess that could be it yes. Its been a while since I struggled with that.
So prefixing with a class name gives the statement a static context - interesting. Probably true.
It is sorta covered in the JavaRanch Style Guide.
subject: static problem.