【问题标题】:java.lang.NumberFormatException: Invalid double: ""?java.lang.NumberFormatException:无效的双精度:“”?
【发布时间】:2015-12-14 23:01:09
【问题描述】:

我不确定如何解决此问题。 我有一个微调器。 When a certain choice is selected then whatever is in the text field (number) I want to use that value for a specific method.

在主要:

EditText temp;
temp = (EditText)findViewById(R.id.editText);



public void onItemSelected(AdapterView<?> parent, View view, int position, long id) 
{

String choice = parent.getSelectedItem().toString();
Double value = Double.parseDouble(temp.getText().toString());
}

在我尝试将 temp 转换为 double 之前一切正常,它会使应用程序崩溃。任何帮助将不胜感激。

我是 ANDROID STUDIO 的新手。

【问题讨论】:

标签: string text double tostring gettext


【解决方案1】:

我认为临时字段是空的(因此是“”),它不能很好地解析为双精度。

【讨论】:

  • 我希望用户在文本字段中输入一个值,那么我是否必须将一个 String 初始化为 temp 才能使其工作?
猜你喜欢
  • 2016-10-05
  • 1970-01-01
  • 1970-01-01
  • 2017-04-21
  • 2013-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多