cancel
Showing results for 
Search instead for 
Did you mean: 

Error "Access via 'Null' object refernce not possible"

Former Member
0 Kudos

Hi

I need to know while binding screen element property with context of View is there anything in property of context which i have to take care the reson y i am asking is i am getting the error which i mentioned in Subject Line.

Thanks

Dhiraj

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Dhiraj.

Cardinality in context node and lead selection is what to take care about.

When you declare Cardinality 0..N and 0..1 no initial (empty) element will be

created for the node. Accessing the node without supplying

data to it can lead to a Null Pointer.

Furthermore, if no lead selection is set on the node the method get_element( ) returns null too.

Hopes this helps a bit.

Cheers,

Sascha

Former Member
0 Kudos

Hi Sascha,

My requirment is as follows i want to set the tray property to None when is displayedand when i click button i shld get the Tray visible for tht thing what i do is in WDOINIT of view where tray is added i am trying to set the property of context which i ahve binded it one of the property of Tray. SO in tht case how shld i set the cardinality and how shld i set the attribute of node and can you jst brief about

' lead selection ' as i am confused with this term .

Thanks

Dhiraj

Former Member
0 Kudos

Hi Dhiraj.

I do so by adding a controlling node to my context which contains all UI property

controlling attributes. This node has cardinality 1..1 which means it must have one

element at run time.

Then I add attributes to that node for visiblity or enabling of UI elements.

In your WDDOINIT you can just access this node and set the attributes.

Remember: You can be sure that you have one element in that node. If you have

set the flag Initialization Lead Selection set to true for the context node you should

be able to get this element by calling get_element( ) without getting the NULL

Pointer. But you also can use the index 1 in this case.

Lead selection is a pointer to the actual selected element in a node (internal table).

This selection is controlled and used by UI elements like table and dwop down. If a

user selects an element in such an UI element the lead selection in the node is

set corresponding.

There are also some methods in if_wd_context_node to handle the lead selection

(move*). Just have a look.

Cheers,

Sascha

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Dhiraj,

I also had similar error initially. It was due to incorrect declaration of OO(Object oriented) ABAP structures and internal table. In my case I tried to access internal table but memory was not allocated to internal table. So I got the same error as yours. So the correct code is as follows. Kindly check out the code and refer to your requirement:

method ADD_NAME .

DATA : lt_temp TYPE if_main_view=>elements_temp.

DATA : lr_element TYPE REF TO if_wd_context_node.

DATA : line LIKE LINE OF lt_temp.

          • Supply data for the node at runtime

REFRESH lt_temp[].

line-name = 'AAA'.

INSERT line INTO TABLE lt_temp.

line-name = 'BBB'.

INSERT line INTO TABLE lt_temp.

lr_element = wd_context->get_child_node( 'Temp' ).

lr_element->bind_table( lt_temp ).

endmethod.

Hope my answer will help you. Hope to get points soon

Cheers,

Darshna.

Former Member
0 Kudos

Hi Darshna,

The declaration is all correct but still there a problem i think the reply frm Sscha is sumthing i can look in to . If you have any idea abt cardinality or u know sumthing abt lead selection do let me know.

Thanks

Dhiraj