Need help: Mysterious initialization behaviour

I subclassed a class UI_ProgressDialog with the class

UI_MultiProcessProgressDialog.

This class defines the following constructor:

public UI_MultiProcessProgressDialog(Frame owner, String title, String header,boolean showTextArea, boolean showProgressLabel,boolean autoClose)

{

super(owner, title, header, showTextArea,showProgressLabel, autoClose);

}

This constructor calls the superclass constructor which calls a method named initGUI. This method is overriden in the subclass UI_MUltiProcessProgressDialog and is being called within the call to the super class constructor of the superclass UI_ProgressDialog.

This initGUI method initializes a class attribute defined in

the subclass UI_MultiProcessProgressDialog. Everything works fine but when the constructor is being processed,

the regarding attribute is reset to null.

If the class attribute is defined as shown here:

Object o;

everything works as it should.

But if the regarding attribute is defined as :

Object o = null;

then the class crashes with a null pointer exception although the attribute has been initialized in the initGUI method.

What's the difference between these two initializations ?

It seems that the initialization of the class attributes is being processed after the constructor respective superclass constructor call. Can someone explain this to me ? Its urgent !!!

[1475 byte] By [sschroeder1] at [2007-9-26 4:03:55]
# 1

not sure if this is relevant, but it might help.

public class Master {

public static void main(String[] args) {

System.out.println("creating base");

Base base = new Base();

System.out.println("creating sub");

Sub sub = new Sub();

}

}

class Base {

public Base() {

System.out.println("in Base constructor");

init();

}

protected void init () {

System.out.println("in Base init");

}

}

class Sub extends Base {

public Sub() {

System.out.println("in Sub constructor");

}

protected void init () {

System.out.println("in Sub init");

}

}

outputs

creating base

in Base constructor

in Base init

creating sub

in Base constructor

in Sub init

in Sub constructor

rob_canoe2 at 2007-6-29 13:01:54 > top of Java-index,Archived Forums,Java Programming...
# 2
Hi! Can you post the code for the initGui method? Also, please use the code tags (click on the special tokens links above the text box where you're typing) so that the code is formatted properly. Makes it much easier to read.Cheers!
amolk at 2007-6-29 13:01:54 > top of Java-index,Archived Forums,Java Programming...
# 3
The behaviour you are getting is correct. I have answered this question in the other thread you posted: http://forum.java.sun.com/thread.jsp?forum=4&thread=160236&start=0&range=100#474405MATT
mattbunch at 2007-6-29 13:01:54 > top of Java-index,Archived Forums,Java Programming...
# 4
Thanks, Matt just revealed the <i>mystery</i>...Thanks a lot.
sschroeder1 at 2007-6-29 13:01:54 > top of Java-index,Archived Forums,Java Programming...
# 5
Aw, Letting all those Duke Dollars go to waste?You may as well hand them out...;-) he..heMatt
mattbunch at 2007-6-29 13:01:54 > top of Java-index,Archived Forums,Java Programming...