0
votes

I have created a context variable called srcCols of type Object

I am assigning a string array to the context variable using this code. The following assignment is done in tJava component

String[] cols = { "This","is","test" };
context.SrcCols = cols;

I am accessing the context variable in tJavaRow using the following code.

String[] Cols = (String[])context.SrcCols;

but when i run the job i get the following error.

java.lang.ClassCastException: java.lang.String cannot be cast to [Ljava.lang.String

What will be the solution for this problem

PS: This job is a Talend Bigdata Spark Job.

1
type of context.SrcCols ? - Rahul Singh
@RahulSingh Its Object - TomG

1 Answers

0
votes

You can try this with it (java 8)

Arrays.stream(objects).toArray(String[]::new);

in your case

String[] Cols = Arrays.stream(context.SrcCols).toArray(String[]::new);