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\Test1.java:114: 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: http://www.amazon.com/exec/obidos/ASIN/0137129394/mobileenterpr-20/
Ringful: http://www.ringful.com/
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.
subject: static problem.
Similar Threads
How to Tile an Image on a JLabel or a JPanel?
Short Example of Fullscreen Graphics
How do I place image in the background of JFrame ?
mandelbrot casse tete
Timer problem...