我是编程新手,我无法弄清楚为什么下面的代码会导致错误。是什么导致v1 java.lang.NumberFormatException:无效的double:?
public void onItemSelected (AdapterView < ? > parent, View view,int position , long id){
double answer;
TextView mTextView = (TextView) findViewById(R.id.textView9);
EditText value;
value = (EditText)findViewById(R.id.editText);
if(position == 0){
v1 = Double.parseDouble(value.getText().toString());
mTextView.setText(Double.toString(answer));
}
答案 0 :(得分:0)
您需要检查您尝试解析的值是否为空
String dv = null;
if (value.getText() != null) {
dv = value.getText().toString ();
}
if(position == 0 && dv != null){
v1 = Double.parseDouble(dv);
mTextView.setText(Double.toString(answer));
}