Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

StringIndexOutOfBoundsException: String index out of range:

Hi,

Please advise me below. Thank you!

 

I have below "out of range" problem after I run my job by using updated source

0683p000009LzAm.jpg

Previously I can run smoothly with below syntax

row1.BOL.substring(0,4).equals("EXDO")||row1.BOL.substring(0,4).equals("DMCQ")?"LCLshipment":"Invalid"

Can not find any clue for that.

Data sample for BOL is 

BOL
CMDUCAD0323962MB
EGLV235800292095
206739726
206756945
206783071
206671602
206535382
EGLV149800286242
HLCUHAM180317960
EXDO6810670633

 

 

 

Labels (2)
1 Solution

Accepted Solutions
manodwhb
Champion II

@szhou1,use the below way and let me know?

 

StringHandling.LEN(row1.BOL)>4 &&(row1.BOL.substring(0,4).equals("EXDO")||row1.BOL.substring(0,4).equals("DMCQ"))?"LCLshipment":"Invalid"

View solution in original post

6 Replies
Anonymous
Not applicable
Author

Hello,

Would you mind posting your job setting screenshots on forum which will be helpful for us to address your issue?

Best regards

Sabrina

manodwhb
Champion II

@szhou1,use the below way and let me know?

 

StringHandling.LEN(row1.BOL)>4 &&(row1.BOL.substring(0,4).equals("EXDO")||row1.BOL.substring(0,4).equals("DMCQ"))?"LCLshipment":"Invalid"

Anonymous
Not applicable
Author

Hi,

 

Thank you for your advise. I run smoothly with syntax - I am wondering why it works when I add "StringHandling.LEN(row1.BOL)>4"?

I have another question - I also have another syntax to filter if BOL# ends with letter such as "X,Y,Z,B". previously everything is good but for now it shows out of range error either. I tried to add "StringHandling.LEN(row1.BOL)>4" but NOT work.

Can you please advise me about this?

0683p000009LzHX.jpg

My current syntax is 

row1.BOL.substring(row1.BOL.length()-1, row1.BOL.length()).equals("X")||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("Y")||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("Z")||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("B")?"Dynamic":"Invalid" 

manodwhb
Champion II

@szhou1,since your data length is less than 4 in row1.BOL for some of the values so that's way you were getting out of range" problem.

 

try the below one and let me know.

row1.BOL.length()>1 &&(row1.BOL.substring(row1.BOL.length()-1, row1.BOL.length()).equals("X")
||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("Y")
||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("Z")
||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("B"))?"Dynamic":"Invalid"

manodwhb
Champion II

@szhou1,since your data length is less than 4 in row1.BOL for some of the values so that's way you were getting out of range" problem.

 

try the below one and let me know.

row1.BOL.length()>1 &&(row1.BOL.substring(row1.BOL.length()-1, row1.BOL.length()).equals("X")
||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("Y")
||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("Z")
||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("B"))?"Dynamic":"Invalid"

Anonymous
Not applicable
Author

StringIndexOutOfBoundsException error is realted to Java substring and it means you are attempting to access a character which would come after the end of the string. If a String is only 4 characters long, attempting to get the substring from index 0 - 8, will throw this exception. substring(beginIndex, endInded) throws IndexOutOfBoundsException if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.