🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #16717

Re: Help: static data member got reset...

#16717
From: peter stevenson
Date: Mon, 25 Jan 1999 00:00
50 lines
1988 bytes

You have move outside the class so become null
Try it like this
 public class MyFrame extends Frame {
    //...
    void someMethod {
       MY_OBJ = new MyObject();
      Main.MY_OBJ.someMethod();  // Main.MY_OBJ becomes null here!

peter
John Yu wrote:

> 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: <36AB8E5E.D22F91EF@xtra.co.nz>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36A8031C.CC5DDA7@objectmastery.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,ad7c1cb07f7c3e7f
X-Google-Attributes: gidf74b3,public
From: peter stevenson <cyber.space@xtra.co.nz>
Subject: Re: Help: static data member got reset...
Date: 1999/01/25
Message-ID: <36AB8E5E.D22F91EF@xtra.co.nz>
X-Deja-AN: 436429913
Content-Transfer-Encoding: 7bit
References: <36A8031C.CC5DDA7@objectmastery.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language