From d793a4f9f7a410aca422ac02e13a73cc64879a0c Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Mon, 11 Nov 2019 08:47:38 +0200 Subject: [PATCH] catch bad numbers when parsing entered amount --- .../ui/activity/NewTransactionItemHolder.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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(); -- 2.39.5