on 04-27-2009 11:40 AM
Hi,
Scenario 1:- I am creating a simple web dynpro project. I inserted a label. Made a Node say N_Label & its attribute say A_label context for that label. I done the mapping. In implementation, I wrote the following code: wdContext.currentN_LabelElement().setA_Label("MyName");
Problem:- It is throwing javaNullPointer Exception.
Scenario 2:- If I create only attribute without node, it work fine.
Please suggest what could be the reason.
Regards
Chander Kararia
Hi Chander,
The issue is related to the cardinality of the Context Node.
In the first scenario, when you create a node, by default the node cardinality is 0..n. which means that when the application will launch it will have 0 elements in this node.
Hence, when you try to refer to the context attribute using:
wdContext.currentN_LabelElement().setA_Label("MyName");
it gives out a null pointer exception, as there are zero elements i.e. no current element in the node.
Thus, for scenario 1, It is advisable to define node cardinality as 1..1 or 1..n.
Regards,
Alka.
PS: This type of question is answered quite a lot time on this forum. Kindly search and then post a new question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Alka,
The solution given by you is correct. Though I did not mentioned that already I tested this with all the cardinalities. Still that was showing the error. So did I posted. Hope, you won't mind.
What I believe that it could be one of the bugs in NWDS or may be something else.
I am just refreshing the cache & restarting NWDS. Let's see does that solve the problem. Let you know.
Regards
Chander Kararia
Hi Chander,
You can resolve the issue either by changing the cardinality or by creating an element of the node explicitly.
Option 1: Change the cardinality of the node N_Label to 1..n so that atleast one element is created by default and when you refer the elament like wdContext.currentN_LabelElement() then the default element ill be reffered.
Option 2: Create a new element and bind it to the node after assigning values:
IPrivate<CompName>.IN_LabelElement element1 = wdContext.nodeN_Label().createN_LabelElement();
element1.setA_Label("MyName");
wdContext.nodeN_Label().addElement(element1);
Hope this helps!!
Cheers,
Arafat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi expert,
if you create one value node then you should set the cardinality 1:1 rather 0:nor any thing.
then you can set value in your current code.
Value node-A cardinality-1:1
attruibute---Name.
you can set lika as below..
wdcontext.currentAElement()..setName("your name");
this code is right...you can try to this code..
thanks
jati
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You have to create the instance for N_Label node before setting the attribute.
IPrivate<view name>.IN_LabelElement ele = wdContext.createN_LabelElement();
ele.setA_label("Label Name");
wdContext.nodeN_Label().addElement(ele);
Regards,
Jaya.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Chander
Check the cardinality of node
Give it 1:n
Regards
Ruturaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
null pointer exception is due to the node element being null.
wdContext.currentN_LabelElement().setA_Label("MyName");
change the node cardinality to 1:1 and have a look to this link :
[http://help.sap.com/saphelp_nwce711/helpdata/en/47/bef93c85f56c68e10000000a42189b/content.htm]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.