This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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.
Have you checked out Aspose?
subject: static problem.
It's not a secret anymore!