cancel
Showing results for 
Search instead for 
Did you mean: 

UDF Error

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

Hi all. im doing a UDF wich no have sintax error but when i execute it if fails. i try yo simulate it in another app. and the error is this. run:

Exception in thread "main" java.lang.NullPointerException

at javaapplication2.Main.main(Main.java:28)

here is the UDF code:

int i_correlativo;

String[] flags = null;

String[] ArrayFlags = null;

ResultList result = null;

ArrayFlags[0] = "85";

ArrayFlags[1] = "86";

ArrayFlags[2] = ResultList.CC;

//Recorro cada posicion del arrayFlags para determinar el valor de los Flags.

try{

for (int j = 0; j < ArrayFlags.length - 2; j++){

if (!(ArrayFlags[j].equals(ResultList.CC))) {

i_correlativo = 85;

for (int i = 0; i < 8; i++) {

if (ArrayFlags[j].equals(String.valueOf(i_correlativo))) {

flags<i> = "1";

i_correlativo++;

} else if (!(flags<i>.equals("1"))) {

flags<i> = "0";

i_correlativo++;

}

}

} else {

for (int x = 0; x < flags.length; x++) {

result.addValue(flags[x]);

}

result.addContextChange();

}

}

}catch(Exception e){

System.out.println(e);

}

Thanks A Lot.

RP

Accepted Solutions (0)

Answers (2)

Answers (2)

prasannakrishna_mynam
Contributor
0 Kudos

Hello,

Your exception Nullpointer raises when ever you are assinging varables wrongly.The following statements are causing the problem.

String[] flags = null;
          String[] ArrayFlags = null;
          ArrayFlags[0] = "85";
         ArrayFlags[1] = "86";
         ArrayFlags[2] = ResultList.CC;

Here you are assigning to array variables with out creating object for String array.You need to create objects for the array statements like

String[] flags =new String[<specify the length>]  (eg:- String[] flags =new String[3]  )
String[]  ArrayFlags =new String[<specify the length>]

The another statement

flags = "1";

you have declared 'flags' as String Array, and you are assigning it like normal varaible. Use index like flags[0]="1" .

Check these cases, which causes NullPointerException.

Regards,

Prasanna

Former Member
0 Kudos

Rodrigo,

In the code first of all we dont use System.out.println(e);

Instead you can use:

AbstractTrace trace=container.getTrace();

trace.addWarning("give the variablename and value here");

Also can you tell what you are trying to do with this udf.

Regards,

---Satish

Former Member
0 Kudos

I don't understand where you are going with that function, but to me it sounds like one of the references in an array is not valid.