Problem unary operator expected

I get the following error
./get_NE05: line 42: [: 4: unary operator expected
Line 42 corresponds to the second IF statement

while [ $I -le $2 ]
do
    echo ${STRING_NAME[$J]}
    J=1
    if [ $I -lt 10 ]; then
         EXT=0$I
    else
         EXT=$I
    fi
    while [ $J -le 4 ]
    do
        echo $I-$J
        #calculating last occurrence
        OCCURRENCE=`grep -io "${STRING_NAME[$J]}" ${1}-0${EXT}.out_bis| wc -l`
        if [ $J -eq 1 ]; then
            OLD_OCCURRENCE[$J]=${OCCURRENCE}
        fi
        if [ ${OCCURRENCE} -ne ${OLD_OCCURRENCE[$J]} ]; then
            echo "error" $OCCURRENCE[$J] $OLD_OCCURRENCE[$J]
        fi
        J=`expr $J + 1`
    done
    I=`expr $I + 1`
done

Any idea what I'm doing wrong?
Thanks,
Sarah

echo your variables to see what values are currently assigned before that line. You can also use set -x/ set +x to check what is going on. You can also try out double brackets etc.

i know why, its because I and J are not set you have to do the following:

I=0
J=0

I=`command`
etc...

I don't think the second if statement is the problem. You would have a problem with the second while before that. J is already declared.

You are setting OLD_OCCURRENCE only when J is 1, but testing it for every value of J. That could be a problem.

On top of that you're treating OCCURRENCE both as a variable and as an array. Which is it?

And what is the starting value of I?