我无法将焦点设置在第一个 edittext 字段(以及下面的其他 3 个字段中)。代码是:
k1_e=(EditText)findViewById(R.id.k1_editText);
k1_e.requestFocusFromTouch();
try{
k1=Float.parseFloat(k1_e.getText().toString());
}catch(Exception e) {
Log.e("logtag", "Exception: " + e.toString());
}
k2_e=(EditText)findViewById(R.id.k2_editText);
try{
k2=Float.parseFloat(k2_e.getText().toString());
}catch(Exception e) {
Log.e("logtag", "Exception: " + e.toString());
}
al_e=(EditText)findViewById(R.id.al_editText);
try{
al=Float.parseFloat(al_e.getText().toString());
}catch(Exception e) {
Log.e("logtag", "Exception: " + e.toString());
}
alconst_e=(EditText)findViewById(R.id.al_const_editText);
try{
al_const=Float.parseFloat(alconst_e.getText().toString());
}catch(Exception e) {
Log.e("logtag", "Exception: " + e.toString());
}
当应用程序在模拟器上执行时,它会自动将焦点设置到最后一个 edittext 字段并抛出异常:
12-29 08:10:05.241: E/logtag(769): Exception: java.lang.NumberFormatException: Invalid float: ""
12-29 08:10:05.261: E/logtag(769): Exception: java.lang.NumberFormatException: Invalid float: ""
12-29 08:10:05.261: E/logtag(769): Exception: java.lang.NumberFormatException: Invalid float: ""
12-29 08:10:05.271: E/logtag(769): Exception: java.lang.NumberFormatException: Invalid float: ""
什么是错误。我是初学者。请帮助