在这个方法中,我返回一个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)
如果this.gyro_x是null你不回什么...
您的代码应该是这样的
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)
| 归档时间: |
|
| 查看次数: |
94 次 |
| 最近记录: |