Why do I get this error message: incomparable types: double and nulltype

Roald Baudoux's icon

Hello,

I am building a function to interpolate eight lists (it's a 3D interpolation with lists considered as edges of a cube).

The lists arrive in different inputs and are put in a 2D array. As the lists might have different lengths and the process begins as soon as a list is received, I first seek the length of longest list. Then prior to interpolate I want to check if the eight values do exist (non-null) otherwise I use zeroes. However when I compile I get an error message for this line

if (items[j][i] == null) {

The error message is: incomparable types: double and
if (items[j][i] == null) {

The complete function is:

//interpolation
    public static double interpolate(int numItems, double[] position, double[][] items) {
        double[] interpolatedValues = new double[numItems];
        for (int i=0; i

I don't understand why I get this error message.

Roald Baudoux's icon

I still don't get it but I don't really need to solve this anymore because in between I have discovered that arrays cannot be resized dynamically and that all values in the array are initialized at allocation time. Therefore I dimension both dimensions of array so to accept lists up to 256 items and there's no need to test for null values anymore. However I still measure the lengths of incoming lists so to avoid unnecessary calculations.

nick rothwell | project cassiel's icon

items is an array of arrays of doubles. Doubles are primitive types in Java (not classes) so can't be null.

Arrays can't be resized in place, but System.arraycopy() will move blocks of array data for you:

Roald Baudoux's icon

Thanks Nick !

nick rothwell | project cassiel's icon

If you want Java interoperability but more modern support for manipulating arrays, consider Python-in-Java:

nick rothwell | project cassiel's icon

(Sorry for the duplicates; cycling74.com wedged for a while there.)