From Thursday, July, 9, 3:00 PM Pacific,
our Community site will be in
read-only mode
through Sunday, July 12th.
Thank you for your patience.

tJavaFlex java.lang.ArrayIndexOutOfBoundsException

Highlighted
Seven 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
Highlighted
Community Manager

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);

View solution in original post


All Replies
Highlighted
Seven Stars

Re: tJavaFlex java.lang.ArrayIndexOutOfBoundsException

The above is done in the main section of tjavaflex btw
Highlighted
Community Manager

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);

View solution in original post

Highlighted
Seven 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. 

Highlighted
Five Stars

Re: tJavaFlex java.lang.ArrayIndexOutOfBoundsException

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

Re: tJavaFlex java.lang.ArrayIndexOutOfBoundsException

Good point rnathan2020! thanks

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

Talend API Designer – Technical Overview

Take a look at this technical overview video of Talend API Designer

Watch Now

Getting Started with APIs

Find out how to get started with APIs

Read