转换是其他类,我正在工作MainActivity
;
当我清除edittext然后输入“-”然后它会产生错误,但是当我输入一些值然后在edittext的第一个位置然后它不会产生错误,请帮助我附上我的错误日志。
Conversion conversion;
conversion = new Conversion();
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
if(edittext.length()!=0){
String Result =conversion.temp(spinner1.getSelectedItemPosition(),
spinner2.getSelectedItemPosition(),edittext.getText().toString());
textView.setText(Result);
}
}
这是我的功能
public String temp(int ddfrom,int ddto,String edittextvalue) {
float s;
float inputValue = Float.parseFloat(edittextvalue);
s = rate*inputValue;
return String.valueOf(s);
}
02-04 12:56:33.029: E/AndroidRuntime(317): Uncaught handler: thread main exiting due to uncaught exception 02-04 12:56:33.119: E/AndroidRuntime(317): java.lang.NumberFormatException: - 02-04 12:56:33.119: E/AndroidRuntime(317): at org.apache.harmony.luni.util.FloatingPointParser.initialParse(FloatingPointParser.java:149) 02-04 12:56:33.119: E/AndroidRuntime(317): at org.apache.harmony.luni.util.FloatingPointParser.parseFloat(FloatingPointParser.java:319) 02-04 12:56:33.119: E/AndroidRuntime(317): at java.lang.Float.parseFloat(Float.java:288) 02-04 12:56:33.119: E/AndroidRuntime(317): at com.sample.unitconverter.Conversion.timee(Conversion.java:651) 02-04 12:56:33.119: E/AndroidRuntime(317): at com.sample.unitconverter.UnitConverter$6.onTextChanged(UnitConverter.java:397) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.widget.TextView.sendOnTextChanged(TextView.java:6131) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.widget.TextView.handleTextChanged(TextView.java:6172) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:6316) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.text.SpannableStringBuilder.sendTextChange(SpannableStringBuilder.java:889) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:352) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:269) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:432) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:409) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:28) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:578) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:174) 02-04 12:56:33.119: E/AndroidRuntime(317): at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:120) 02-04 12:56:33.119: E/AndroidRuntime(317): at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:231) 02-04 12:56:33.119: E/AndroidRuntime(317): at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:57) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.os.Handler.dispatchMessage(Handler.java:99) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.os.Looper.loop(Looper.java:123) 02-04 12:56:33.119: E/AndroidRuntime(317): at android.app.ActivityThread.main(ActivityThread.java:4363) 02-04 12:56:33.119: E/AndroidRuntime(317): at java.lang.reflect.Method.invokeNative(Native Method) 02-04 12:56:33.119: E/AndroidRuntime(317): at java.lang.reflect.Method.invoke(Method.java:521) 02-04 12:56:33.119: E/AndroidRuntime(317): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 02-04 12:56:33.119: E/AndroidRuntime(317): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 02-04 12:56:33.119: E/AndroidRuntime(317): at dalvik.system.NativeStart.main(Native Method)