From: Reimar Döffinger Date: Sat, 13 Feb 2016 15:11:37 +0000 (+0100) Subject: Add a few null checks. X-Git-Url: http://gitweb.fperrin.net/?p=Dictionary.git;a=commitdiff_plain;h=97e23e394d0f6a3150534487e2a174b974b6e230 Add a few null checks. --- diff --git a/src/com/hughes/android/dictionary/DictionaryActivity.java b/src/com/hughes/android/dictionary/DictionaryActivity.java index e00f5dd..5b5f9e1 100644 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@ -389,7 +389,7 @@ public class DictionaryActivity extends ActionBarActivity { for (final Index index : dictionary.indices) { final String searchToken = index.sortedIndexEntries.get(0).token; final IndexEntry entry = index.findExact(searchToken); - if (!searchToken.equals(entry.token)) { + if (entry == null || !searchToken.equals(entry.token)) { Log.e(LOG, "Couldn't find token: " + searchToken + ", " + entry.token); } } @@ -1095,8 +1095,11 @@ public class DictionaryActivity extends ActionBarActivity { if (keyCode == KeyEvent.KEYCODE_ENTER) { Log.d(LOG, "Trying to hide soft keyboard."); final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), - InputMethodManager.HIDE_NOT_ALWAYS); + View focus = getCurrentFocus(); + if (focus != null) { + inputManager.hideSoftInputFromWindow(focus.getWindowToken(), + InputMethodManager.HIDE_NOT_ALWAYS); + } return true; } return super.onKeyDown(keyCode, event); diff --git a/src/com/hughes/android/dictionary/PreferenceActivity.java b/src/com/hughes/android/dictionary/PreferenceActivity.java index a415d87..2d66bf9 100644 --- a/src/com/hughes/android/dictionary/PreferenceActivity.java +++ b/src/com/hughes/android/dictionary/PreferenceActivity.java @@ -104,9 +104,12 @@ public class PreferenceActivity extends android.preference.PreferenceActivity dirs += "\n" + f.getAbsolutePath(); } } else { - String externalFilesDir = getApplicationContext().getExternalFilesDir(null).getAbsolutePath(); - if (new File(externalFilesDir).canWrite()) - dirs += "\n" + externalFilesDir; + File efd = getApplicationContext().getExternalFilesDir(null); + if (efd != null) { + String externalFilesDir = efd.getAbsolutePath(); + if (new File(externalFilesDir).canWrite()) + dirs += "\n" + externalFilesDir; + } } new AlertDialog.Builder(this).setTitle(getString(R.string.error)) .setMessage(getString(R.string.chosenNotWritable) + dirs)