on 08-18-2010 2:36 PM
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.
Hi Santosh,
the string is obvisiously not 185 characters long. You should assure that before by asking: if (x.length >= 185) ...
Regards,
Udo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> 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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.