我正在尝试计算女性的BMR,但是旋转器出现错误:
09-01 22:08:52.373: E/AndroidRuntime(344): at com.fps.iHealthFirst.BMRCalculator.onClick(BMRCalculator.java:286)
09-01 22:08:52.373: E/AndroidRuntime(344): at android.view.View.performClick(View.java:2485)
09-01 22:08:52.373: E/AndroidRuntime(344): at android.view.View$PerformClick.run(View.java:9080)
09-01 22:08:52.373: E/AndroidRuntime(344): at android.os.Handler.handleCallback(Handler.java:587)
09-01 22:08:52.373: E/AndroidRuntime(344): at android.os.Handler.dispatchMessage(Handler.java:92)
09-01 22:08:52.373: E/AndroidRuntime(344): at android.os.Looper.loop(Looper.java:123)
09-01 22:08:52.373: E/AndroidRuntime(344): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-01 22:08:52.373: E/AndroidRuntime(344): at java.lang.reflect.Method.invokeNative(Native Method)
09-01 22:08:52.373: E/AndroidRuntime(344): at java.lang.reflect.Method.invoke(Method.java:507)
09-01 22:08:52.373: E/AndroidRuntime(344): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-01 22:08:52.373: E/AndroidRuntime(344): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-01 22:08:52.373: E/AndroidRuntime(344): at dalvik.system.NativeStart.main(Native Method)
以下是我的代码,试图获取静坐、轻度运动、中度运动和重度运动的旋钮值:
private void calculateWomen(){
String f1a = etft.getText().toString();
String f2a = etin.getText().toString();
String f3a = etweight.getText().toString();
String f4a = etage.getText().toString();
if ( ( f1a.isEmpty() || f2a.isEmpty() || f3a.isEmpty() || f4a.isEmpty() ) )
// call for custom toast
viewErrorToast();
else{
// Metric Formula for BMR (Women) English Unit
//655 + ( 4.3379 x weight in pounds ) +
//( 4.6980 x height in inches ) - ( 4.6756 x age in years )
String age, in, ft, weight;
Double answer;
age = etage.getText().toString();
in = etin.getText().toString();
ft = etft.getText().toString();
weight = etweight.getText().toString();
if (spinnerText.equals("Sedentary")){
//actAnswer = "1.2";
answer = ( ( 665 + ( 4.3379 * Double.parseDouble( weight ) ) +
( 4.6980 * ( Double.parseDouble( in ) ) * 12 + Double.parseDouble( ft ) )
- ( 4.6756 * Double.parseDouble( age ) ) ) * 1.2);
BigDecimal bd = BigDecimal.valueOf(answer);
bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
etanswer.setText(bd.toString());
}
else if (spinnerText.equals("Lightly Active")){
//actAnswer = "1.375";
answer = ( ( 665 + ( 4.3379 * Double.parseDouble( weight ) ) +
( 4.6980 * ( Double.parseDouble( in ) ) * 12 + Double.parseDouble( ft ) )
- ( 4.6756 * Double.parseDouble( age ) ) ) * 1.375);
BigDecimal bd = BigDecimal.valueOf(answer);
bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
etanswer.setText(bd.toString());
}
else if (spinnerText.equals("Moderately Active")){
// actAnswer = "1.55";
answer = ( ( 665 + ( 4.3379 * Double.parseDouble( weight ) ) +
( 4.6980 * ( Double.parseDouble( in ) ) * 12 + Double.parseDouble( ft ) )
- ( 4.6756 * Double.parseDouble( age ) ) ) * 1.55);
BigDecimal bd = BigDecimal.valueOf(answer);
bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
etanswer.setText(bd.toString());
}
else if (spinnerText.equals("Heavily Active")){
// actAnswer = "1.725";
answer = ( ( 665 + ( 4.3379 * Double.parseDouble( weight ) ) +
( 4.6980 * ( Double.parseDouble( in ) ) * 12 + Double.parseDouble( ft ) )
- ( 4.6756 * Double.parseDouble( age ) ) ) * 1.725);
BigDecimal bd = BigDecimal.valueOf(answer);
bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
etanswer.setText(bd.toString());
}
// call for custom toast
viewBMRSavedToast();
}
} // end of calculateWomen method
如果您注意到任何问题,请通知我,谢谢。非常感激。
onClick(View v)
方法中而不是calculateWomen()
。请发布您的onClick()方法并指出第286行:"at com.fps.iHealthFirst.BMRCalculator.onClick(BMRCalculator.java:286)
"。 - Sam