返回Double类型的值时出错?

And*_*pha 0 java android

在这个方法中,我返回一个Double类型的值,但有一个错误说"方法

必须返回Double类型的值"???

代码:

public class Gyro extends Activity {

Double gyro_X;
Double gyro_Y;
Double gyro_Z;

public Double getGyro_X() {
    if (this.gyro_X == null) {
        Toast.makeText(this, ""+gyro_XIsNullText, ToastdurationShort).show();
    } else { 
    return this.gyro_X;
    }
}
Run Code Online (Sandbox Code Playgroud)

Jav*_*ave 5

如果this.gyro_xnull你不回什么...
您的代码应该是这样的

public Double getGyro_X() {
    if (this.gyro_X == null) {
        Toast.makeText(this, ""+gyro_XIsNullText, ToastdurationShort).show();
        return null;
        //Or maybe: throw new NullPointerException();
    } else { 
    return this.gyro_X;
    }
}
Run Code Online (Sandbox Code Playgroud)