]> git.ktnx.net Git - mobile-ledger.git/commitdiff
catch bad numbers when parsing entered amount
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 11 Nov 2019 06:47:38 +0000 (08:47 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Mon, 11 Nov 2019 06:47:38 +0000 (08:47 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java

index 763c508f65beca634d59a43450abce928a09c4e1..387a25486d5089cbd209076fb3eb25aa38e574f4 100644 (file)
@@ -239,8 +239,20 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
                     String amount = String.valueOf(tvAmount.getText());
                     amount = amount.trim();
 
-                    if (!amount.isEmpty()) item.getAccount()
-                                               .setAmount(Float.parseFloat(amount));
+                    if (!amount.isEmpty()) {
+                        try {
+                            item.getAccount()
+                                .setAmount(Float.parseFloat(amount));
+                        }
+                        catch (NumberFormatException e) {
+                            Logger.debug("new-trans", String.format(
+                                    "assuming amount is not set due to number format exception. " +
+                                    "input was '%s'",
+                                    amount));
+                            item.getAccount()
+                                .resetAmount();
+                        }
+                    }
                     else item.getAccount()
                              .resetAmount();