Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
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

Labels (5)
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