0

I have an apk to load payments, where transfer details are attached. Among several options there is a field where an amount with decimals is entered. When trying to edit the amount, it shows this error and returns me to the previous screen.

enter image description here

code

}
        iv6.setVisibility(View.VISIBLE);


        etvalor.setText(min);

        s = Float.parseFloat(min);
        Float Bsf = Float.parseFloat(tasa)*s;
        //Toast.makeText(getApplicationContext(), tasa.toString(), Toast.LENGTH_LONG).show();
        Locale currentLocale = Locale.GERMAN;
        otherSymbols = new DecimalFormatSymbols(currentLocale);
        otherSymbols.setDecimalSeparator(',');
        otherSymbols.setGroupingSeparator('.');

        df = new DecimalFormat("#,##0.00", otherSymbols);
        String numberAsString = df.format(Bsf);
        etBsf.setText(numberAsString);
        etBsfpromo.setText(numberAsString);
        String tasaAsString = df.format(Float.parseFloat(tasa));
        tvTasa.setText(tasaAsString);
        final String finalTasa = tasa;
        etvalor.addTextChangedListener(new TextWatcher() {

            public void onTextChanged(CharSequence s, int start, int before,
                                      int count) {
                if(!s.equals("") ) {
                    //do your work here
                }
            }

I will add more text that might be of interest.

                public void beforeTextChanged(CharSequence s, int start, int count,
                                          int after) {

            }

            public void afterTextChanged(Editable s) {
                Float w = null;
                if(checkboxpromo.isChecked()){
                    w = Float.parseFloat(String.valueOf(etvalor))*(1+(Float.parseFloat(valorp.get(spinnerpromo.getSelectedItemPosition()))/100));
                    valorpromo = valorp.get(spinnerpromo.getSelectedItemPosition());

                }else {
                    w = Float.parseFloat(String.valueOf(etvalor));
                    valorpromo="0";
                }
                Float w1 = Float.parseFloat(finalTasa)*w;
                String numberAsString3 = df.format(w1);
                etBsf.setText(numberAsString3);
                etBsfpromo.setText(numberAsString3);
            }
            
        });

I appreciate any input!

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Lilibeth
  • 111
  • 4
  • And why would you be wanting to parse that large text-filled String as a number? The exception shows the String that you're trying to format, and again, it simply doesn't make sense. – Hovercraft Full Of Eels Jul 26 '21 at 19:57
  • Sorry, I was trying to show it. – Lilibeth Jul 26 '21 at 19:58
  • OK, no problem -- but now, which parsing line in the `afterTextChanged(...)` method is the one throwing the exception? And again, it should be obvious by the stack trace String why the exception is being thrown, the issue is why you think that String should represent a number. Please comment back. – Hovercraft Full Of Eels Jul 26 '21 at 20:07
  • It must represent a number because it refers to an amount with decimals (amount in currency, example: the user can enter amounts such as 30,000.30). Thank you. – Lilibeth Jul 26 '21 at 21:05
  • Again, which line in the code throws the exception? The stack trace will tell you. Also, make no assumptions about what the String *must* represent as again the stack trace will tell you (and is telling you) exactly what String you are trying to parse as number. Currently, the stack trace is telling you that you're trying to parse "faranjit.currency.edittext.CurrencyEditText{.....}" as a number (the "..." represent more text). Does this look like a number to you? Use your debugger to find out why your assumptions are wrong. – Hovercraft Full Of Eels Jul 26 '21 at 21:10
  • Since only you have the working program, only you can really find this out and fix it. Good luck. – Hovercraft Full Of Eels Jul 26 '21 at 21:10
  • In order to get any value from an EditText, we take help of [EditeText#getText()](https://developer.android.com/reference/android/widget/EditText#getText()) method which returns an [Editable](https://developer.android.com/reference/android/text/Editable) which again implements CharSequence interface. So, we need to call Editable#toString() method to get the text being written in an EditText. Your final call should be `etvalor.getText().toString()` instead of `String.valueOf(etvalor)`. In the crashlog, you can see you are getting EditText#toString() as a return value which is not formattable. – Jay Jul 26 '21 at 22:23

0 Answers0