Androelpha
Androelpha

Reputation: 387

checking whether or not a variable of type double is null or not, generates error

I'm just checking if a value of a double variable is null or not, strangely, an error raised saying "operator == is undefined for double"?

Code:

public double getGyro_X() {
    if (this.gyro_X == null) {
        Toast.makeText(this, ""+gyro_XIsNullText, ToastdurationShort).show();
    } else {
    return this.gyro_X;
    }
}

Upvotes: 0

Views: 3205

Answers (2)

Tom
Tom

Reputation: 4180

this.gyro_X apparantly is an instance variable, it will be initialized automatically to 0.

If you want to be able to check against null, you'll have to use a Double (= wrapper class for double).

Just for clarity: doubles are primitives, Doubles are objects. Primitives can't be null, so you can't compare them against null. Objects you can compare to null.

Upvotes: 1

ngesh
ngesh

Reputation: 13501

Then its of type double and not of type Double.. and double cannot be null

Upvotes: 1

Related Questions