Java Snippet error

Hi team,

I am facing an error with Java snippet. Does anyone have any idea?

input column:
table2
3
8
6
4

Custom variable:
double previousrow;

Code:
if (ROWINDEX == 0) {
out_outp = null;
} else {
out_outp = previousrow[n];
}
n=n+1;
previousrow[n] = c_table2;

Error:
The exception is caused by line 35 of the snippet.
WARN Java Snippet 0:285:2 Exceptions in the code caused missing rows to be output.

Thanks!

Hi,

there are a few things concerning your code snippet:

previousrow should be null in your case. To fix it simply do

double previousrow = new double[10];

Note that ROWCOUNT is not available at the time of compilation and that you cannot use it here for instantiation. A better solution would be to use an ArrayList (see here).
Next you should also instantiate n. A better way would be to use the ROWINDEX as this is the index of the currently processed row (starting at 0).

Cheers,
Moritz