Article View: borland.public.jbuilder.java.language
Article #16690Help: static data member got reset...
From: John Yu
Date: Fri, 22 Jan 1999 00:00
Date: Fri, 22 Jan 1999 00:00
37 lines
1586 bytes
1586 bytes
I experience this problem a couple of times. Please look at the
following code segments:
public class Main {
static MyObject MY_OBJ;
static public void main(String[] args) {
MY_OBJ = new MyObject();
MyFrame frame = new MyFrame();
frame.setVisible(true);
}
}
public class MyFrame extends Frame {
//...
void someMethod {
Main.MY_OBJ.someMethod(); // Main.MY_OBJ becomes null here!
//...
}
}
MyFrame.someMethod() is called to event a GUI event. I can't
understand why Main.MY_OBJ becomes null at that point. Moreover, this
is a random problem. Sometimes it works fine but sometimes doesn't.
Is it a bug in the Java runtime?
Or is it because that the main thread has ended and the Main *class*
object got garbage collected? (This is a weird thought...)
What complicates the problem more is if I use the debug feature in
JBuilder to step thru the code, Main.MY_OBJ always retains its value
and doesn't have a problem!
I'm using JBuilder 2.01 and jdk116_borland.
--
John
Technical Details
Message-ID:
<36A8031C.CC5DDA7@objectmastery.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,ad7c1cb07f7c3e7f,start X-Google-Attributes: gidf74b3,public From: John Yu <jyu@objectmastery.com> Subject: Help: static data member got reset... Date: 1999/01/22 Message-ID: <36A8031C.CC5DDA7@objectmastery.com> X-Deja-AN: 435505753 Content-Transfer-Encoding: 7bit X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: ObjectMastery Pty. Ltd. Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language