currency_edittext icon indicating copy to clipboard operation
currency_edittext copied to clipboard

Crash in formatter with no easy way to catch it

Open StainlessStlRat opened this issue 6 years ago • 6 comments

java.lang.NumberFormatException: For input string: " 0002" at java.lang.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1306) at java.lang.Double.parseDouble(Double.java:547) at faranjit.currency.edittext.CurrencyEditText.format(CurrencyEditText.java:192) at faranjit.currency.edittext.CurrencyEditText.access$300(CurrencyEditText.java:22) at faranjit.currency.edittext.CurrencyEditText$1.onTextChanged(CurrencyEditText.java:171) at android.widget.TextView.sendOnTextChanged(TextView.java:8448) at android.widget.TextView.handleTextChanged(TextView.java:8510) at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:10764) at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:1208) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:578) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:509) at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:508) at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:845) at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:198) at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:183) at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:345) at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:91) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154)

StainlessStlRat avatar Sep 15 '17 05:09 StainlessStlRat

This happens during the "TextChanged" event, the "text" variable is formatted to eliminate the symbols and spaces. But it fails to delete the space at the beginning of the value, in your case "0002".

I decided to create my own class based on CurrencyEditText and added the line:

text = text.replaceAll ("\ s +", "");

and that works.

I also added that line in the "getCurrencyDouble" function because an exception was also presented.

These are my modifications so they can be added to this library:

        String text = s.toString();
        text = text.replace(groupDivider, '\u0020').replace(monetaryDivider, '\u0020')
                .replace(".", "").replace(" ", "")
                .replace(currencySymbol, "").trim();
        text = text.replaceAll("\\s+", "");

AmadoMata avatar Aug 15 '18 17:08 AmadoMata

Since this is not being maintained I will fork this and create an independent project.

AlexJuca avatar Nov 01 '18 22:11 AlexJuca

Hi, Sorry for my late response. I cant reproduce this crash :(

faranjit avatar Jan 18 '19 21:01 faranjit

Hi, This is happening on the Android PIE for me 😢

lesio avatar Feb 04 '19 14:02 lesio

Hi, for me happening only on Android Pie. The edit text insert automatically blank space and .trim or replace not remove this.

rgielow avatar Mar 14 '19 12:03 rgielow

Thanks @AmadoMata - this fixes the issue for me :)

Runman44 avatar May 14 '19 13:05 Runman44