Adding custom (user defined) java code - "cannot be resolved" error

Highlighted
Four Stars

Adding custom (user defined) java code - "cannot be resolved" error

Hi everyone,
I am trying to use user defined method in tJavaRow component in a job. It seems to me like I'm doing everything by the book ("TalendOpenStudio_UG_41b_EN.pdf", pages 267 to 272 in pdf), but I'm still getting "cannot be resolved" error when running a job.
This is my setup:
1. I've added the java code in Repository / Code / Routines / MyCode. I've created 2 methods: SqlINstr, SqlINnum and I kept the example helloExample code as well. Enclosed that in MyCode public class and tried to create all comments as required:
public class MyCode {

/**
* SqlINstr: Emulate SQL IN operator.
*
*
* {talendTypes} boolean | Boolean
*
* {Category} User Defined
*
* {param} String("value") input: The string need to be printed.
*
* {param} String[] ("value2","value3") pattern: The string array to match at least one.
*
* {example} SqlINstr (String EntryValue, String[] MatchingConditions)
*
*/
public static boolean SqlINstr(String EntryValue, String[] CondSet) {
int cnt = 0;
boolean MatchFound = false;
while (cnt < CondSet.length) {
if (EntryValue.equals(CondSet)) {MatchFound = true;}
cnt++;
}
return MatchFound;
}

/**
* SqlINstr: Emulate SQL IN operator
*
*
* {talendTypes} boolean | Boolean
*
* {Category} User Defined
*
* {param} Integer(1) input: The integer need to be printed.
*
* {param} Integer[] (100, 101) pattern: The integer array to match at least one.
*
* {example} SqlINnum (int EntryValue, int[] MatchingConditions)
*
*/
public static boolean SqlINnum(int EntryValue, int[] CondSet) {
int cnt = 0;
boolean MatchFound = false;
while (cnt < CondSet.length) {
if (EntryValue == CondSet) {MatchFound = true;}
cnt++;
}
return MatchFound;
}
/**
* helloExample: not return value, only print "hello" + message.
*
*
* {talendTypes} String
*
* {Category} User Defined
*
* {param} string("world") input: The string need to be printed.
*
* {example} helloExemple("world") # hello world !.
*/
public static void helloExample(String message) {
if (message == null) {
message = "World"; //$NON-NLS-1$
}
System.out.println("Hello " + message + " !"); //$NON-NLS-1$ //$NON-NLS-2$
}
}

2. I've added the code in tJavaRow component to use those methods:
String[] AcrGL = {"DND","DOD","SPD","VAG"};
if (SqlINstr(input_row.acr, AcrGL))
{output_row.saldorsd_gl = input_row.saldorsd;}

But, when I run the job I'm getting: "MyCode cannot be resolved" error? Is this because of some error in the code, or I didn't specify enough where the application should look fot the code?
Thanx.
Employee

Re: Adding custom (user defined) java code - "cannot be resolved" error

You must precise the package when you call your routine. Just type "Routine" and CTRL+Space for autocompletion you should get full path to your method.
Four Stars

Re: Adding custom (user defined) java code - "cannot be resolved" error

Ok, I've modified now tJavaRow with the following:
String[] AcrGL = {"DND","DOD","SPD","VAG"};
if (Routines.MyCode.SqlINstr(input_row.acr, AcrGL))
{output_row.saldorsd_gl = input_row.saldorsd;}

But I am still getting the same error. When I type CTRL+SPACE after typing "Routines." for autocompletion all I get is an empty window with the header: No basic/template/swt proposals?
Four Stars

Re: Adding custom (user defined) java code - "cannot be resolved" error

Aaah.. It's case sensitive.. Sorry Smiley Very Happy it works allright! (It's "routines" instead of a "Routines")
Muchos gracias camsellem.
One Star

Re: Adding custom (user defined) java code - "cannot be resolved" error

Hi, I'm having the same problem here...
There is no typo error or case sensitive.
I didn't even write into the code manually.
I added it into the expression filter.
and in expression filter, my method is visible and available.
but when i tried to run the job, it gave me that MyMethod cannot be resolved
I tried to import the class manually too....
Please.... tell me how can I fix this.....
Thanks
Community Manager

Re: Adding custom (user defined) java code - "cannot be resolved" error

Hi, I'm having the same problem here...
There is no typo error or case sensitive.
I didn't even write into the code manually.
I added it into the expression filter.
and in expression filter, my method is visible and available.
but when i tried to run the job, it gave me that MyMethod cannot be resolved
I tried to import the class manually too....
Please.... tell me how can I fix this.....
Thanks

Right click on the job name and select 'set routines dependencies' option to check your custom routine is there, add it if not.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Definitive Guide to Data Quality

Create systems and workflow to manage clean data ingestion and data transformation.

Download

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads