I have below code with some parent/child class definition (all of them are sequences)
class A;
my_ral_block my_block;
task pre_start();
uvm_config_db#(my_ral_block)::get(null, "*", "my_ral_block", my_block);
endtask;
task body();
...
endtask;
endclass
class B extends A;
task pre_start();
super.pre_start();
...
endtask;
task body();
super.body();
...
endtask;
taak my_func();
my_block.my_reg.write();
....
endtask
endclass
class C extends A;
B my_b;
task pre_start();
super.pre_start();
my_b = new();
endtask;
task body();
super.body();
my_b.my_func();
...
endtask;
endclass
And I got the error is Error-[NOA] Null object access in the code my_b.my_func() in class C. I don’t know how to fix this. Can anyone help me on this ?
This likely has nothing to do with inheritance, rather the way sequence C get started without calling pre_start(). If you are going to use pre_body and pre_start (which we recommend you avoid and just use the class constructor new() ) you need to understand the rules about when the do or do not get called.
You need to determine which class variable is null when you try to reference it. The way you transcribed the error message is not clear. Try easySV’s suggestion.
We recommend not using pre_start unless you understand and need the functionality of it not being called in certain cases. Otherwise, just put the code in new().