• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need to split a string on new line and the colon":". Getting java.lang.ArrayIndexOutOfBoundsExceptio  RSS feed

 
Zayed Khan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a string value in variable ncacustast "XXIBE_PART_NUMBER_G:236587
Description:zayed33
Quantity:4"

I need to split them on new line and colon(":")

I am able to achieve it using the below code but eventually get java.lang.ArrayIndexOutOfBoundsException: 3.
Can you please help?

Code:

for(String key_nca : ncafield.keySet()) {
if(key_nca.matches(".*ncafields_.*")) {
int l =0;
if(IBE_logEnabled) IBEUtil.log("xxibeCCkdSalesHelp.jsp", "key_nca for 2 = "+ key_nca);
%>
<TR>

<TD width="120" nowrap class="tableDataCell"><%=msgMgr.getMessage("IBE", ncafield.get(key_nca).toString())%>:</TD>
<td align="right">
<% if (mandatfld[j]) {%>
<IMG name="imgreq1<%=j%>" width="16" height="16" border="0" src="/OA_MEDIA/jtfureq.gif">
<input type="hidden" id="<%=key_nca_fld%><%=i%><%=j%><%=l%>" name="<%=key_nca_fld%><%=i%><%=j%><%=l%>" value=true>
<% }else{ %>
<input type="hidden" id="<%=key_nca_fld%><%=i%><%=j%><%=l%>" name="<%=key_nca_fld%><%=i%><%=j%><%=l%>" value=false>
<%}%>

<%
if(IBE_logEnabled) IBEUtil.log("xxibeCCkdSalesHelp.jsp", "Before 1st if:input-ncacustast = "+ ncacustast);
if(ncacustast!=null){
String ncacusast1=ncacustast.replaceAll("\\n","|");
if(IBE_logEnabled) IBEUtil.log("xxibeCCkdSalesHelp.jsp", "Inside replace before substring:ncacusast1 = "+ ncacusast1);
ncacusast1 = ncacusast1.substring(0, ncacusast1.length()-1);
if(IBE_logEnabled) IBEUtil.log("xxibeCCkdSalesHelp.jsp", "After substring:ncacusast1 = "+ ncacusast1);
String[] fnd_message = ncacusast1.trim().split("\\|");
if(!fnd_message.equals("")){
if(IBE_logEnabled) IBEUtil.log("xxibeCCkdSalesHelp.jsp", "Before 1st for:input-fnd_message = "+ fnd_message[i]);
if(IBE_logEnabled) IBEUtil.log("xxibeCCkdSalesHelp.jsp", "After 1st for:input-fnd_message = "+ fnd_message[i]);
StringTokenizer st=new StringTokenizer(fnd_message[i],":");
while(st.hasMoreTokens())
{
String splitValue=st.nextToken();
if(IBE_logEnabled) IBEUtil.log("xxibeCCkdSalesHelp.jsp", "Splitvalue test: splitValue[p] = "+ splitValue);

}
i++;
}

}
if(IBE_logEnabled) IBEUtil.log("xxibeCCkdSalesHelp.jsp", "Zayed - After if ");
%>
<INPUT type="text" size="20" maxlength="40" id="<%=key_nca_fld%><%=i%><%=j%>" name="<%=key_nca_fld%><%=i%><%=j%>" value=""> </TD>
</TR>
<%
j++;
}
}
 
Zayed Khan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Log:

9:36:30:995 [xxibeCCkdSalesHelp.jsp] key_nca for 2 = ncafields_0
9:36:30:998 [xxibeCCkdSalesHelp.jsp] Before 1st if:input-ncacustast = XXIBE_PART_NUMBER_G:236587
Description:zayed33
Quantity:4

9:36:31:2 [xxibeCCkdSalesHelp.jsp] Inside replace before substring:ncacusast1 = XXIBE_PART_NUMBER_G:236587|Description:zayed33|Quantity:4|
9:36:31:10 [xxibeCCkdSalesHelp.jsp] After substring:ncacusast1 = XXIBE_PART_NUMBER_G:236587|Description:zayed33|Quantity:4
9:36:31:19 [xxibeCCkdSalesHelp.jsp] Before 1st for:input-fnd_message = XXIBE_PART_NUMBER_G:236587
9:36:31:23 [xxibeCCkdSalesHelp.jsp] After 1st for:input-fnd_message = XXIBE_PART_NUMBER_G:236587
9:36:31:26 [xxibeCCkdSalesHelp.jsp] Splitvalue test: splitValue[p] = XXIBE_PART_NUMBER_G
9:36:31:29 [xxibeCCkdSalesHelp.jsp] Splitvalue test: splitValue[p] = 236587
9:36:31:33 [xxibeCCkdSalesHelp.jsp] Zayed - After if
9:36:31:40 [xxibeCCkdSalesHelp.jsp] key_nca for 2 = ncafields_1
9:36:31:43 [xxibeCCkdSalesHelp.jsp] Before 1st if:input-ncacustast = XXIBE_PART_NUMBER_G:236587
Description:zayed33
Quantity:4

9:36:31:47 [xxibeCCkdSalesHelp.jsp] Inside replace before substring:ncacusast1 = XXIBE_PART_NUMBER_G:236587|Description:zayed33|Quantity:4|
9:36:31:50 [xxibeCCkdSalesHelp.jsp] After substring:ncacusast1 = XXIBE_PART_NUMBER_G:236587|Description:zayed33|Quantity:4
9:36:31:53 [xxibeCCkdSalesHelp.jsp] Before 1st for:input-fnd_message = Description:zayed33
9:36:31:57 [xxibeCCkdSalesHelp.jsp] After 1st for:input-fnd_message = Description:zayed33
9:36:31:60 [xxibeCCkdSalesHelp.jsp] Splitvalue test: splitValue[p] = Description
9:36:31:63 [xxibeCCkdSalesHelp.jsp] Splitvalue test: splitValue[p] = zayed33
9:36:31:67 [xxibeCCkdSalesHelp.jsp] Zayed - After if
9:36:31:70 [xxibeCCkdSalesHelp.jsp] key_nca for 2 = ncafields_4
9:36:31:74 [xxibeCCkdSalesHelp.jsp] Before 1st if:input-ncacustast = XXIBE_PART_NUMBER_G:236587
Description:zayed33
Quantity:4

9:36:31:77 [xxibeCCkdSalesHelp.jsp] Inside replace before substring:ncacusast1 = XXIBE_PART_NUMBER_G:236587|Description:zayed33|Quantity:4|
9:36:31:80 [xxibeCCkdSalesHelp.jsp] After substring:ncacusast1 = XXIBE_PART_NUMBER_G:236587|Description:zayed33|Quantity:4
9:36:31:84 [xxibeCCkdSalesHelp.jsp] Before 1st for:input-fnd_message = Quantity:4
9:36:31:87 [xxibeCCkdSalesHelp.jsp] After 1st for:input-fnd_message = Quantity:4
9:36:31:91 [xxibeCCkdSalesHelp.jsp] Splitvalue test: splitValue[p] = Quantity
9:36:31:94 [xxibeCCkdSalesHelp.jsp] Splitvalue test: splitValue[p] = 4
9:36:31:98 [xxibeCCkdSalesHelp.jsp] Zayed - After if
9:36:31:101 [xxibeCCkdSalesHelp.jsp] key_nca for 2 = ncafields_2
9:36:31:105 [xxibeCCkdSalesHelp.jsp] Before 1st if:input-ncacustast = XXIBE_PART_NUMBER_G:236587
Description:zayed33
Quantity:4

9:36:31:108 [xxibeCCkdSalesHelp.jsp] Inside replace before substring:ncacusast1 = XXIBE_PART_NUMBER_G:236587|Description:zayed33|Quantity:4|
9:36:31:111 [xxibeCCkdSalesHelp.jsp] After substring:ncacusast1 = XXIBE_PART_NUMBER_G:236587|Description:zayed33|Quantity:4
9:36:31:253 [ibeCZzdError.jsp] Message: 3
9:36:31:257 [ibeCZzdError.jsp] Stack:

java.lang.ArrayIndexOutOfBoundsException: 3
at _xxibeCCkdSalesHelp._jspService(_xxibeCCkdSalesHelp.java:2281)
at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:473)
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In these two lines

where do you set the value of i. It appears to have been set to 3 and your fnd_message array has less than 3 elements.
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solution:
- UseCodeTags.
- Don't use scriptlets.
 
Zayed Khan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I resolved the error.
"for(String key_nca : ncafield.keySet()) { " is my main for loop used to create the DIVs dynamically.
I readjusted the position with if else condition so as to take my split function out of the for loop.
This resolved the issue.

Thanks for the suggestions. Really appreciate.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!