Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit 1adfa99

Browse files
author
Evgenii Kanivets
committed
#119[30m]. Fix an NFE at AddAccountActivity.addAccount.
1 parent cdee239 commit 1adfa99

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,4 @@ dependencies {
6464
androidTestCompile 'com.crittercism.dexmaker:dexmaker:1.4'
6565
androidTestCompile 'com.crittercism.dexmaker:dexmaker-dx:1.4'
6666
androidTestCompile 'com.crittercism.dexmaker:dexmaker-mockito:1.4'
67-
}
67+
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/account/AddAccountActivity.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,31 @@ public boolean onCreateOptionsMenu(Menu menu) {
6565
public boolean onOptionsItemSelected(MenuItem item) {
6666
switch (item.getItemId()) {
6767
case R.id.action_done:
68-
addAccount();
69-
70-
setResult(RESULT_OK);
71-
finish();
68+
if (addAccount()) {
69+
setResult(RESULT_OK);
70+
finish();
71+
} else showToast(R.string.wrong_number_text);
7272
return true;
7373

7474
default:
7575
return super.onOptionsItemSelected(item);
7676
}
7777
}
7878

79-
private void addAccount() {
79+
private boolean addAccount() {
8080
String title = etTitle.getText().toString().trim();
81-
double initSum = Double.parseDouble(etInitSum.getText().toString().trim());
81+
82+
double initSum;
83+
try {
84+
initSum = Double.parseDouble(etInitSum.getText().toString().trim());
85+
} catch (NumberFormatException e) {
86+
e.printStackTrace();
87+
return false;
88+
}
89+
8290
String currency = (String) spinner.getSelectedItem();
8391

8492
Account account = new Account(title, initSum, currency);
85-
accountController.create(account);
93+
return accountController.create(account) != null;
8694
}
87-
}
95+
}

0 commit comments

Comments
 (0)