
Anonymous
Not applicable
2011-08-04
08:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[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
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
1,766 Views
- « Previous Replies
-
- 1
- 2
- Next Replies »
1 Solution
Accepted Solutions

Anonymous
Not applicable
2011-08-08
06:25 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Sorry my mistake
row4.house_no.trim().length()<40 ?row4.house_no.trim() : row4.house_no.trim().substring(0,39)
Sorry my mistake
row4.house_no.trim().length()<40 ?row4.house_no.trim() : row4.house_no.trim().substring(0,39)
1,658 Views
11 Replies

Specialist
2011-08-04
11:18 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
substring throws that error if the String length if less than 40 because it tries to get 40 characters. Instead use StringHandling.LEFT(row4.house_no,40) on its own. (Also, your expression is actually setting the house_no to blank if it's longer than 40 characters.)
1,655 Views

Anonymous
Not applicable
2011-08-05
08:13 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for your answer, i will try as soon as possible
Best Regards
Bahadir
Thanks for your answer, i will try as soon as possible
Best Regards
Bahadir
1,658 Views

Anonymous
Not applicable
2011-08-08
05:38 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi again,
I have tried your suggestion as, StringHandling.LEFT(row4.house_no,40) but i am getting
"Exception in component tMap_14
java.lang.NullPointerException
at routines.StringHandling.LEFT(StringHandling.java:184)" error. Do you have any idea to solve this issue?
Best Regards
Bahadir
I have tried your suggestion as, StringHandling.LEFT(row4.house_no,40) but i am getting
"Exception in component tMap_14
java.lang.NullPointerException
at routines.StringHandling.LEFT(StringHandling.java:184)" error. Do you have any idea to solve this issue?
Best Regards
Bahadir
1,658 Views

Anonymous
Not applicable
2011-08-08
06:01 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
row4.house_no.trim().length()>40 ?"" : row4.house_no.trim().substring(0,39)
row4.house_no.trim().length()>40 ?"" : row4.house_no.trim().substring(0,39)
1,658 Views

Anonymous
Not applicable
2011-08-08
06:20 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for you answer, i have tried as you wrote and i got
"Exception in component tMap_14
java.lang.StringIndexOutOfBoundsException: String index out of range: 39
at java.lang.String.substring(Unknown Source)" error?
Best Regards
Bahadir
Thanks for you answer, i have tried as you wrote and i got
"Exception in component tMap_14
java.lang.StringIndexOutOfBoundsException: String index out of range: 39
at java.lang.String.substring(Unknown Source)" error?
Best Regards
Bahadir
1,658 Views

Anonymous
Not applicable
2011-08-08
06:25 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Sorry my mistake
row4.house_no.trim().length()<40 ?row4.house_no.trim() : row4.house_no.trim().substring(0,39)
Sorry my mistake
row4.house_no.trim().length()<40 ?row4.house_no.trim() : row4.house_no.trim().substring(0,39)
1,659 Views

Anonymous
Not applicable
2011-08-08
07:07 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
After 158 row i am getting ""Exception in component tMap_14 java.lang.NullPointerException" again! ?
Best Regards
Bahadir
After 158 row i am getting ""Exception in component tMap_14 java.lang.NullPointerException" again! ?
Best Regards
Bahadir
1,658 Views

Anonymous
Not applicable
2011-08-08
07:10 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Add Relational.ISNULL(row4.house_no)?"":row4.house_no.trim().length()<40 ?row4.house_no.trim() : row4.house_no.trim().substring(0,39)
Add Relational.ISNULL(row4.house_no)?"":row4.house_no.trim().length()<40 ?row4.house_no.trim() : row4.house_no.trim().substring(0,39)
1,658 Views

Anonymous
Not applicable
2011-08-08
07:53 AM
Author
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
This one works great, thanks. But can you explain how does it work, i could not figure out?
Best Regards
Bahadir
This one works great, thanks. But can you explain how does it work, i could not figure out?
Best Regards
Bahadir
1,658 Views

- « Previous Replies
-
- 1
- 2
- Next Replies »