cancel
Showing results for 
Search instead for 
Did you mean: 

Getting arrayindexoutofboundsexception when accessing string

Former Member
0 Kudos

I have a major problem and a short deadline so please help. I'm accessing CRM using a function someone else developed. I input two strings (a productnumber and a one letter code) I should get two strings back (an "X" if the product exists otherwise "" and the productname) Im using below code to test this.

wdThis.wdGetCreateCampController().executeZ_Existance_Check();

IWDMessageManager manager = wdComponentAPI.getMessageManager();

String testExists = "";

String testProdText = "";

try

{

testExists = wdGetContext().currentExists_OutputElement().getExists();

testProdText =wdGetContext().currentExists_OutputElement().getProd_Text();

}

catch(Exception ex)

{

manager.reportException(ex.toString()":Exists="testExists":ProdText="testProdText, false);

}

manager.reportSuccess("Exists="testExists":ProdText="+testProdText);

It works as far as filling testExists (it gets filled with an "X" which shows in the generated message), but when I try to fill testProdText I get an arrayindexoutofboundsexception.

NWDS agrees with me that getProd_Text should return a string. If i put a "." after it suggest string methods (trim, substr and so on)

I've tried to delete the model and reimport it to no avail. Please help. Im at my wits end.

Regards

Carl Schultze

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

testExists = wdGetContext().currentExists_OutputElement().getExists(); works

testProdText =wdGetContext().currentExists_OutputElement().getProd_Text(); throws an exception

Yashpal
Active Contributor
0 Kudos

Hi,

this code can throw nullpointer exception but not arrayindexoutofBounds

check wdContext.currentExist_poutputelemet().equals(null)

if yes then set the testprodtext as u wish else

wdContext.currentExist_poutputelemet().getProd_text()

Thanks,

yashpal

Former Member
0 Kudos

Im quite aware that this code shouldn't throw an ArrayIndexOutOfBoundsException, but alas, it does. The currentExistsOutputElement never equals null since I can use getExists() and always either get an "X" or an empty string returned.

Thanks for your input so far

Former Member
0 Kudos

Hi Carl,

1) Can you post your exception trace here?

2) Can you comment that particular line & confirm if the application runs without an exception if that line is commented?

Best Regards,

Nibu.

Former Member
0 Kudos

Hi Nibu

I've confirmed that its that particular line (getProd_Text) that throws the exception.

Error stacktrace:

java.lang.ArrayIndexOutOfBoundsException: -1

at com.sap.mw.jco.JCO$Record.getString(JCO.java:12003)

at

com.sap.aii.proxy.framework.core.JcoBaseTypeData.getElementValueAsString(JcoBaseTypeData.java:669)

at

com.sap.tc.webdynpro.modelimpl.dynamicrfc.DynamicRFCModelClass.getAttributeValueAsString(DynamicRFCModelClass.java:409)

at

z_existance_check_model2.Z_Existance_Check_Output.getProd_Text(Z_Existance_Check_Output.java:149)

at

com.customerCompany.crm.wdp.InternalCreateCamp$Exists_OutputElement.getProd_Text(InternalCreateCamp.java:3747)

at

com.customerCompany.crm.wdp.InternalCreateCampView$Exists_OutputElement.getProd_Text(InternalCreateCampView.java:3115)

at

com.customerCompany.crm.CreateCampView.onActionTestValidation(CreateCampView.java:518)

at

com.customerCompany.crm.wdp.InternalCreateCampView.wdInvokeEventHandler(InternalCreateCampView.java:3287)

at

com.sap.tc.webdynpro.progmodel.generation.IControllerDelegate$LegacyAdapter.wdInvokeEventHandler(IControllerDelegate.java:51)

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:100)

at

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

at

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

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:391)

at

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

at

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

at

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

at

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

at

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

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:37)

at

com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)

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:94)

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

Regards

Carl

Former Member
0 Kudos

Hi Carl,

Sorry, I am not sure about why this happens. But as the trace say, I feel it has got something to do with your model. Make sure that the model you are using is in sync with the BAPI/RFC at the backend. A model re-import and restarting of the server <b>may</b> help you,

Best Regards,

Nibu.

Former Member
0 Kudos

Thanks Nibu. Restarting the server, how unneccessary it always seems , fixed my problem. Points assigned.

Regards

Carl

HuseyinBilgen
Active Contributor
0 Kudos

Same problem and same solution. As it because I've added the model node by reimporting model. J2EE servers needs a restart to update model metadata.

Answers (1)

Answers (1)

Yashpal
Active Contributor
0 Kudos

Hi,

can u post at which line exception occured..

yashpal

Message was edited by: Yashpal Gupta