cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Null Pointer Exception for the following code.

senthil_kumar29
Participant
0 Kudos

Hello Friends,

Getting Null Pointer Exception for the following code.

IWDMessageManager mgr = wdComponentAPI.getMessageManager();

String Language;

String Country;

Locale currentLocale;

ResourceBundle messages;

currentLocale = new Locale(wdContext.getChildNode("locale",0).getCurrentElement().getAttributeAsText("language"),

wdContext.getChildNode("locale",0).getCurrentElement().getAttributeAsText("country"));

messages = ResourceBundle.getBundle("MessageBundle",currentLocale);

mgr.reportException(messages.getString("greetings"),false);

mgr.reportException(messages.getString("inquiry"),false);

mgr.reportException(messages.getString("farewell"),false);

-


The Exception Cycle:

java.lang.NullPointerException

at com.sap.tutorial.ex.I18NView.onActionShowMessage(I18NView.java:156)

at com.sap.tutorial.ex.wdp.InternalI18NView.wdInvokeEventHandler(InternalI18NView.java:149)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)

at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleAction(WebDynproMainTask.java:101)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:304)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:659)

at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)

at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:251)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:55)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:390)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:264)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:347)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:325)

at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:887)

at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:241)

at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)

at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)

at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)

ThanQ for Ur time.

Cheers.. Sam

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Sam,

I think your locale node is empty and thus you are getting this null pointer exception.

Just write this line before

currentLocale = new Locale(wdContext.getChildNode("locale",0).getCurrentElement().getAttributeAsText("language"),

wdContext.getChildNode("locale",0).getCurrentElement().getAttributeAsText("country"));

wdComponentAp\PI.getMessageManager().reportSuccess(wdContext.nodeLocale().size());

Comment all the lines for the time being.

If you get the size as 0 then your locale node is empty and thus resulting into null pointer exception.

Comment the code in bold

currentLocale = new Locale(wdContext.getChildNode("locale",0).getCurrentElement().getAttributeAsText("language"),

wdContext.getChildNode("locale",0).getCurrentElement().getAttributeAsText("country"));

messages = ResourceBundle.getBundle("MessageBundle",currentLocale);

mgr.reportException(messages.getString("greetings"),false);

mgr.reportException(messages.getString("inquiry"),false);

mgr.reportException(messages.getString("farewell"),false);

Regards,

Murtuza

senthil_kumar29
Participant
0 Kudos

Hi,

The Context Node Locale have cardinality 1..1, Since I use it as Input element in UI.

If I use cardinality 0..1, then My input element is grayed, can't input anything.

I think the cardinality property 1..1 is throwing the error, Since it is empty initially.

Do we have any solution to come around this issue.

Cheers,

Senthil

Former Member
0 Kudos

Hi Sam,

May i know in which method have you written that above code. Is it in WDDoInit(). Even 1:1 won't give you that error.

Also tell me which is the line no. 156 in I18NView.java.

Warm Regards,

Murtuza

senthil_kumar29
Participant
0 Kudos

Hi,

The error has been rectified, when I access the context using typed methods instead of generic.

Cheers,

Sam