tJavaFlex java.lang.ArrayIndexOutOfBoundsException

Six Stars

tJavaFlex java.lang.ArrayIndexOutOfBoundsException

Hi, I'm trying to parse strings into key-value pairs in a tJavaFlex so they can be loaded by tContextLoad in Talend Studio 6.4.1

 

tSubJob - loads a config file and outputs the variables as a string  i.e. "Username;admin;" "Password;123;" etc

|

tJavaFlex - split into key-values

|

tContextLoad - load into environment variables

 

the code in tJavaFlex is 

 

String [] kvPairs = row6.contextString.split(";");
row5.key = kvPairs[0];
row5.value = kvPairs[1];

 

But i get the error below. row6 is definitely the input row and 5 the output. 

 

Exception in component tJavaFlex_1
java.lang.ArrayIndexOutOfBoundsException: 1
at tRunJob_2Process(CreateStressRateInMSS.java:4225)
at tJava_1Process(CreateStressRateInMSS.java:3416)
at runJobInTOS(CreateStressRateInMSS.java:5407)
at main(CreateStressRateInMSS.java:4960)
[FATAL]: tJavaFlex_1 1
java.lang.ArrayIndexOutOfBoundsException: 1
at tRunJob_2Process(CreateStressRateInMSS.java:4225)
at tJava_1Process(CreateStressRateInMSS.java:3416)
at runJobInTOS(CreateStressRateInMSS.java:5407)
at main(CreateStressRateInMSS.java:4960)
[statistics] disconnected

 

Anyone any ideas?

 

Thanks

 


Accepted Solutions
Sixteen Stars

Re: tJavaFlex java.lang.ArrayIndexOutOfBoundsException

This suggests that your String being split does not have a semicolon in it. The java.lang.ArrayIndexOutOfBoundsException exception is a standard Java exception indicating that the array does not have the number of elements you are expecting. Can you just print the value held by row6.contextString in your tJavaFlex....

 

System.out.println(row6.contextString);

All Replies
Six Stars

Re: tJavaFlex java.lang.ArrayIndexOutOfBoundsException

The above is done in the main section of tjavaflex btw
Sixteen Stars

Re: tJavaFlex java.lang.ArrayIndexOutOfBoundsException

This suggests that your String being split does not have a semicolon in it. The java.lang.ArrayIndexOutOfBoundsException exception is a standard Java exception indicating that the array does not have the number of elements you are expecting. Can you just print the value held by row6.contextString in your tJavaFlex....

 

System.out.println(row6.contextString);
Six Stars

Re: tJavaFlex java.lang.ArrayIndexOutOfBoundsException

Many thanks rhall when i inspected the output it was a null value for one of the values which was causing the issue. Have managed to fix it now. 

Five Stars

Re: tJavaFlex java.lang.ArrayIndexOutOfBoundsException

Good one. Actually I would enclose this kind of iffy code in try {} catch{} block.
Six Stars

Re: tJavaFlex java.lang.ArrayIndexOutOfBoundsException

Good point rnathan2020! thanks