这行android代码有什么问题? [英] What is wrong with this line of android code?

查看:87
本文介绍了这行android代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

answer.setText(Double.toString(calculate(firstUnit.getSelectedItem().toString(), secondUnit.getSelectedItem().toString(), Double.parseDouble(unitSize.getText().toString()))));



这是



Here is

public double calculate(String unit1, String unit2, double d){
    return 1.23;
}




它给出了数字格式异常,而1.23只是我出于测试目的给出的数字.假定答案是textview,并且firstUnit和secondUnit是Spinners,unitSize是edittext小部件.




It gives a number format exception and 1.23 is just a number i gave for testing purposes. Assume that answer is a textview, and firstUnit and secondUnit are spinners and unitSize is an edittext widget.

推荐答案

如果给定参数失败,我敢打赌它是一个.请尝试格式化您的代码,如下所示:
I bet it''s one if the given arguments that fail. Please try to format your code like this:
double dUnitSize = Double.parseDouble(unitSize.getText().toString());
double dValue = calculate(
      firstUnit.getSelectedItem().toString(),
      secondUnit.getSelectedItem().toString(),
      dUnitSize
);
answer.setText(dValue);


您很快就会发现问题所在.


you''ll soon find out which line the problem is.


这篇关于这行android代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆