无效双。在android系统数字格式异常 [英] Invalid Double. Number format exception in android

查看:254
本文介绍了无效双。在android系统数字格式异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的XML格式。

I have this in xml.

<EditText
                android:id="@+id/creditlimitfield2"
                android:hint="0"
                android:inputType="numberDecimal" />

因此​​,对于的EditText的默认值是0。

So, the default value for edittext is 0.

在code,我有这样的

in code, I have this

creditlimit = (EditText) findViewById(R.id.creditlimitfield2);
double credit_limit = Double.valueOf(creditlimit.getText().toString());

另外,我曾尝试:

Alternately, I have tried:

double credit_limit = Double.parseDouble(creditlimit.getText().toString());

double credit_limit = new Double(creditlimit.getText().toString());

当我运行程序,它给出的误差

When I run the program, It gives the error of

Numberformatexception. Invalid double "".

请提醒的是,字段不为空。任何建议将是有益的。

Please be reminded that the field is not empty. Any suggestions would be helpful.

我见过很多问题,几乎与它,用非常少的答案,没有人帮忙解决我的病情。所以,请不要没有检查其他问题也将其标记为类似的问题。

I have seen many questions,almost similar to it, with very less answers and none of them help solving my condition. So, Please do not tag it as "Similar Question" without checking other questions too.

推荐答案

的getText()不返回的Andr​​oid里面的值:提示。所以,你想一个空字符串转换为双。使用的android:文本属性,而不是

getText() does not return the value inside android:hint. So you are trying to convert an empty string as double. use android:text property instead.

<EditText
    android:id="@+id/creditlimitfield2"
    android:text="0"
    android:inputType="numberDecimal" />

这篇关于无效双。在android系统数字格式异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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