File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Murach's Java Servlets and JSP this week in the Servlets 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.
I agree. Here's the link:
subject: static problem.
Similar Threads
How to Tile an Image on a JLabel or a JPanel?
mandelbrot casse tete
Timer problem...
Short Example of Fullscreen Graphics
How do I place image in the background of JFrame ?