From: Damyan Ivanov Date: Mon, 11 Nov 2019 06:47:38 +0000 (+0200) Subject: catch bad numbers when parsing entered amount X-Git-Tag: v0.11.0~73 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=d793a4f9f7a410aca422ac02e13a73cc64879a0c;p=mobile-ledger.git catch bad numbers when parsing entered amount --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java index 763c508f..387a2548 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java @@ -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();