Forums > Java

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

April 30, 2012 | 7:53 am

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.


April 30, 2012 | 10:09 am

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.


April 30, 2012 | 10:21 am

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)


April 30, 2012 | 12:11 pm

Thanks Nick !


April 30, 2012 | 3:09 pm

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

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


April 30, 2012 | 4:29 pm

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

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


April 30, 2012 | 4:29 pm

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


Viewing 7 posts - 1 through 7 (of 7 total)