Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] String index out of range error

Hi all;
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.
Best Regards
Bahadir
Labels (4)
11 Replies
Anonymous
Not applicable
Author

Hi
It will first check row4.house_no is null or not, if null then it will assign blank values
If not null, it will check the legth of the house_no, if less than 40 no change
else
row4.house_no= row4.house_no.trim().substring(0,39) //take only the first 40 characters
as in java the numbering starts from 0 so the max should be 39
hope it clarifies you.
Anonymous
Not applicable
Author

Hi,
Thank you for your answer, it helps very much.
Best Regards
Bahadir