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

Apr 30, 2012 at 7:53am

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

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.

#63305
Apr 30, 2012 at 10:09am

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.

#228344
Apr 30, 2012 at 10:21am

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:

http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/System.html#arraycopy(java.lang.Object,%20int,%20java.lang.Object,%20int,%20int)

#228345
Apr 30, 2012 at 12:11pm

Thanks Nick !

#228346
Apr 30, 2012 at 3:09pm

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

https://github.com/cassiel/net.loadbang.jython

#228347
Apr 30, 2012 at 4:29pm

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

https://github.com/cassiel/net.loadbang.jython

#228348
Apr 30, 2012 at 4:29pm

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

#228349

You must be logged in to reply to this topic.