cancel
Showing results for 
Search instead for 
Did you mean: 

Java udf problem

Former Member
0 Kudos

Hello sdn

I have a udf but it gives an error : int cannot be dererenced.

can anyone suggest.

below is the udf

int pos = a.indexOf("RT");

if(pos.equals("-1"))

return("does not exists");

else

return("exists");

Please suggest.

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

justin_santhanam
Active Contributor
0 Kudos

Hi,

Your coding needs to be changed. pos you defined as integer and you are using eQuals function(String function) with int.

Try the below code.



if(a.indexOf("RT") == -1)
return("does not exists");
else
return("exists");

if you want to use your same logic, then try the below UDF


int pos = a.indexOf("RT");
if(pos ==-1)
return("does not exists");
else
return("exists");

raj.

Answers (2)

Answers (2)

Former Member
0 Kudos

pos is an integer.

in the comparison - .equals() you are comparing an integer with a string...apples and oranges cannot be compared...

try

if (pos == -1)

Arvind R

Former Member
0 Kudos

Thanks guys.

Former Member
0 Kudos

better way..


if ( a.indexOf("RT") > -1 )
{
  return "exists";
}
else 
{
return("does not exists");
}