Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

String index out of range error

Hello,

 

I am trying to read data from xml file and write them to Mysql db. In my db House_no field's data type is String(40). In xml file there are some house no values that longer than 40 and i want to cut all the values that are greater than 40.
so i try the code below in tMap but i got "java.lang.StringIndexOutOfBoundsException: String index out of range: 40 at java.lang.String.substring(Unknown Source)" error?
row4.house_no.length()>40 ?"" : row4.house_no.substring(0,40)
Do you have any idea what cause this error, or a better way to take 0-40 character without using tJavaRow.

 

thanks

iosman

 

 

___________________________

0xc000000f

1 Reply
JR1
Creator III
Creator III

Try putting you ternary statement in the correct order and add a "null" check to it:

row4.house_no != null && row4.house_no.length() > 40 ? row4.house_no.substring(0,40) : row4.house_no