cancel
Showing results for 
Search instead for 
Did you mean: 

UDF error: StringIndexOutOfBoundsException: String index out of range: 185

Former Member
0 Kudos

Hi,

I am working on a UDF to split the entries of file.

I am getting below mentioned issue,

The message is: Exception [java.lang.StringIndexOutOfBoundsException: String index out of range: 185 in class

Structure of my file is,

String contractNo = x.substring(0,10); //1-10 SAP contract reference

String quantity = x.substring(10,25); //11-25 Quantity

String price = x.substring(25,40); //26-40 Price

String delperiod = x.substring(40,46); //41-46 Delivery period e.g. YYYYMM

String condate = x.substring(46,54); //47-54 Contract date e.g. YYMMDD

String shipwts = x.substring(54,57); //55-57 Shipped weights e.g. DWT/EWT

String mtype = x.substring(57,58); //58 Market Type D/E

String cif = x.substring(58,73); //59-73 CIF price

String comtype = x.substring(73,77); //74-77 comtype e.g. ZRAW

String rejreason = x.substring(77,97); //78-97 Reject reason

String type = x.substring(97,98); //98 Type, A =create, B=amend, C= delete

String usrname = x.substring(98,110); //99-110 User Name

String impdate = x.substring(110,118); //111-118 Date, e.g. YYYYMMDD, imported as Quote date

String imptime = x.substring(118,124); //119-124 Time e.g. HHMMSS, imported as Quote time HH:MM

String vafrdate = x.substring(177,185); //177,185 Date, e.g. YYYYMMDD, valid from date

Example Lines of code used for offsetting,

if ( delperiod.substring(4,6).equals("01") && vafrdate.substring(181,185).equals("0101") )

Structure of input file,

0040000305    -153000.000         20.00020110120100817DWTD          0.000ZRAW                    ANHUK        20100817165602                                                     20110101

Guys,

any idea, what mistake i am doing in above code(probably some offsetting mistake).....

regards.

santosh.

Accepted Solutions (1)

Accepted Solutions (1)

udo_martens
Active Contributor
0 Kudos

Hi Santosh,

the string is obvisiously not 185 characters long. You should assure that before by asking: if (x.length >= 185) ...

Regards,

Udo

Former Member
0 Kudos

Hi,

when u mention ,

the string is obvisiously not 185 characters long.

Do u mean the below mentioned string. it is 185 char length.

Or do we mean, permitted length is not 185.

0040000305    -153000.000         20.00020110120100817DWTD          0.000ZRAW                    ANHUK        20100817165602                                                     20110101

pls guide.

Answers (1)

Answers (1)

stefan_grube
Active Contributor
0 Kudos

> if ( delperiod.substring(4,6).equals("01") && vafrdate.substring(181,185).equals("0101") )

for delperiod you did it right, for vafrdate wrong.

Maybe you look again and find the issue by yourself?

Former Member
0 Kudos

Guys,

I am new to java........ pls forgive me for silly questions....

Now, good thing is.....the problem got solved.

I was in a confusion in declaring, i thought the offsetting starts like (181,185) ,

But, it starts from 0 in java.

so, the mistake was, instead of below code,

if ( delperiod.substring(4,6).equals("01") && vafrdate.substring(181,185).equals("0101") )

correct code,

if ( delperiod.substring(4,6).equals("01") && vafrdate.substring(4,8).equals("0101") )

tak.

santosh.