为什么我会得到
错误:不兼容的类型:Double不能转换为Float
用下面的方法?
bmi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Float weightKg,heightmeter1,heightmeter2,TotalHeight,BMI;
String sweight = kg.getText().toString();
weightKg = Float.parseFloat(sweight);
String sfeet = feet.getText().toString();
float heightFeet = Float.parseFloat(sfeet);
heightmeter1 = heightFeet *0.3048;
String sinch = inch.getText().toString();
float heightInch = Float.parseFloat(sinch);
heightmeter2 =heightInch*0.0254;
TotalHeight = heightmeter1+heightmeter2;
BMI = weightKg + (TotalHeight*TotalHeight);
displaybmi.setText(" Your BMI Is = "+BMI+" ");
}
});
Android Studio在构建输出中向我展示
C:\Users\USER\Desktop\Social_Media\app\src\main\java\com\example\social_media\MainActivity.java:73: 错误:不兼容的类型:Double不能转换为Float
heightmeter1 = heightFeet *0.3048;
^
C:\Users\USER\Desktop\Social_Media\app\src\main\java\com\example\social_media\MainActivity.java:77: 错误:不兼容的类型:Double不能转换为Float
heightmeter2 =heightInch*0.0254;
^