cancel
Showing results for 
Search instead for 
Did you mean: 

StringIndexOutOfBoundException In UDF in mapping

Former Member
0 Kudos

Hi ,

I have a UDF via which I am taking the input string and for every 132 characters of input string I split in show it in a different line of an idoc.

It is working fine for 2 lines .However when I get 3 lines i.e. anything more then

395 characters I get this error

StringIndexOutOfBoundException

following is the code I am using in the udf.

public void deriveTEXT(String[] a,ResultList result,Container container){

for(int i=0;i<a.length;i++)

{

int len=a<i>.length();

int variant=132;

int count=len/variant;

int initial=0;

int fin=0;

if(count>=1)

{

fin=variant;

}

else

{

fin=a<i>.length();

}

for(int j=0;j<count;j++)

{

result.addValue(a<i>.substring(initial,fin));

initial=fin;

fin=2*fin;

}

result.addValue(a<i>.substring(initial,a<i>.length()));

if(i<a.length-1)

result.addContextChange();

}

Kindly help.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi ,

Just small change required .

your code

for(int j=0;j<count;j++)

{

result.addValue(a.substring(initial,fin));

initial=fin;

fin=2*fin;

}

Change it to

for(int j=0;j<count;j++)

{

result.addValue(a.substring(initial,fin));

initial=fin;

fin=fin+132;

}

Thanks ,

Suvarna

Award pts if it helps .

Former Member
0 Kudos

Bang on Target ....Silly mistake ...

Believe it or not ..this thing went unnoticed from dev ,qa ,UAT ,and now in production.

Thanks Suvarna

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Deepak,

Try this..

<i>Change the following int len=a.length(); to</i>

int len = a[ i ].length();

ignore the space in between [ ]

Regards,

Sumit

Message was edited by:

Sumit Khetawat

Former Member
0 Kudos

Hi Deepak,

This error coours when for example check word.length() and make sure that it is greater than the index that you are checking. The index must be between 0 and s.length()-1.

Regards,

Subhasha

justin_santhanam
Active Contributor
0 Kudos

Deepak,

Why u are using Queue here ,are u going to get multiple inputs . Also in ur code first line in loop u are using for(int i=0;i<a.length;i++) and in second line u are using int len= a.length(). Both are misleading , can u please clarify?

Best regards,

raj.

Former Member
0 Kudos

Sharma,

Its complalining about the substring functionality. It is failing there. So please check that.

---Satish