开发者

double and int in Eclipse

I am very new person to study in Android and I forget many Java program. Here I have a problem I executed the program in Eclipse today.

public void cvOnClick (View cvView) {
    EditText KilogramsInput = (EditText) findViewById(R.id.Kilograms);
    EditText HeightInput = (EditText) findViewById(R.id.Height);
    TextView BmiOutput = (TextView) findViewById(R.id.Bmi);
    DecimalFormat BmiFormat = new DecimalFormat(".#####");
    Double H开发者_运维百科eightdouble = Math.pow(Integer.parseInt(HeightInput.getText().toString()), 2);          

    String outcome = BmiFormat.format(Integer.parseInt(KilogramsInput.getText().toString())/Heightdouble);
    BmiOutput.setText(outcome);
}

As the original purpose of this program that should be square the number of height. The execution in Eclipse there is no error. But when I put the data(decimal) in the AVD, it shows: the application has stopped unexpectedly.

Pls let me know what can I do at this moment?

Thanks for your all help! brad


You're using Integer.parseInt(), but it gets confused when you put in a double instead of an int. Use Double.parseDouble() instead of Integer.parseInt() and it should work.


If you enter a non integer value in the kilograms or height edit text you are going to get an exception because your are trying to parse them as integers. Use Double.parseDouble() instead of Integer.parseInt()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜