🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Problems with references to objects

#16606
From: Vladimir Olenin
Date: Sun, 31 Jan 1999 00:00
72 lines
2398 bytes
Hi,

Roughly speaking i have the following:

class A{
  SubA subA;

  A(){
   ...
  }

// !!! NOTE that subA is constructed outside A constructor
  init(B b){
    subA = new SubA();
    .....
  }
....
}

class B{
  SubA subA;

  B(A a){
    this.subA = a.subA;
  }

  ActionListener someAdapter = new ActionListener(){
    public void actionPerformed(ActionEvent e){
      D d = subA.getSomeObject();
      .......
    }
  }
}

Now, all classes are initialized as follows:

class MainClass{
  A a = new A();
  B b = new B(a);

  MainClass(){
    a.init(b);
    ...
  }
  
}

After construction of MainClass is competed i can fire an action. But
then i get null pointer exception in inner class someAdapter of B class
when i try to use subA class to getSomeObject. 
When i checked this out, it turned out that subA in B class is null
indeed while subA in A class is not null.

So, where is the problem? I now that this code is a bit complicated and
possibly there is a way to make it simpler, but i can't see the reasons
WHY this can't work. All i do is transfer reference to object subA from
A to B class. It shouldn't matter that when someAdapter class is
initialized, subA = null, since by the moment event is fired (func
actionPerformed is run) subA is NOT null because it have been previously
initialized in func A.init(). Can anyone here clear this out to me,
please?

Thanks for you attention, time and possible efforts to help me,

                          Vladimir

-- 
>~~~~~~~~<=============>~~~~~~~~<
Be yourself no matter what they say...
Join in Java community now!
http://www.geocities.com/SiliconValley/Heights/9815
>~~~~~~~~<=============>~~~~~~~~<
Technical Details
Message-ID: <36B3A1CB.63576B20@collegemail.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,9d1f263a64040fc7,start
X-Google-Attributes: gid111d45,public
X-Google-Thread: f74b3,9d1f263a64040fc7,start
X-Google-Attributes: gidf74b3,public
From: Vladimir Olenin <keenonjava@collegemail.com>
Subject: Problems with references to objects
Date: 1999/01/31
Message-ID: <36B3A1CB.63576B20@collegemail.com>
X-Deja-AN: 438858924
Content-Transfer-Encoding: 7bit
X-Accept-Language: en,ru
Content-Type: text/plain; charset=koi8-r
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language,borland.public.jbuilder.java.swing