File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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
Test1.display.callSerially(this);
^
1 error
com.sun.kvem.ktools.ExecutionException
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
author
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static problem.