From: Thad Hughes Date: Wed, 8 Feb 2012 23:44:40 +0000 (-0800) Subject: Fix NPE when dictDir was not a dir. X-Git-Url: http://gitweb.fperrin.net/?p=Dictionary.git;a=commitdiff_plain;h=a58f08cad61598fb5cbb45b87ed8fa0a4317e5ef Fix NPE when dictDir was not a dir. --- diff --git a/src/com/hughes/android/dictionary/DictionaryApplication.java b/src/com/hughes/android/dictionary/DictionaryApplication.java index d36e99d..25a5f44 100644 --- a/src/com/hughes/android/dictionary/DictionaryApplication.java +++ b/src/com/hughes/android/dictionary/DictionaryApplication.java @@ -256,27 +256,31 @@ public class DictionaryApplication extends Application { // Pick them up and put them at the end of the list. final List toAddSorted = new ArrayList(); final File[] dictDirFiles = getDictDir().listFiles(); - for (final File file : dictDirFiles) { - if (file.getName().endsWith(".zip")) { - if (DOWNLOADABLE_NAME_TO_INFO.containsKey(file.getName().replace(".zip", ""))) { - file.delete(); + if (dictDirFiles != null) { + for (final File file : dictDirFiles) { + if (file.getName().endsWith(".zip")) { + if (DOWNLOADABLE_NAME_TO_INFO.containsKey(file.getName().replace(".zip", ""))) { + file.delete(); + } } + if (!file.getName().endsWith(".quickdic")) { + continue; + } + if (newDictionaryConfig.dictionaryInfoCache.containsKey(file.getName())) { + // We have it in our list already. + continue; + } + final DictionaryInfo dictionaryInfo = Dictionary.getDictionaryInfo(file); + if (dictionaryInfo == null) { + Log.e(LOG, "Unable to parse dictionary: " + file.getPath()); + continue; + } + + toAddSorted.add(file.getName()); + newDictionaryConfig.dictionaryInfoCache.put(file.getName(), dictionaryInfo); } - if (!file.getName().endsWith(".quickdic")) { - continue; - } - if (newDictionaryConfig.dictionaryInfoCache.containsKey(file.getName())) { - // We have it in our list already. - continue; - } - final DictionaryInfo dictionaryInfo = Dictionary.getDictionaryInfo(file); - if (dictionaryInfo == null) { - Log.e(LOG, "Unable to parse dictionary: " + file.getPath()); - continue; - } - - toAddSorted.add(file.getName()); - newDictionaryConfig.dictionaryInfoCache.put(file.getName(), dictionaryInfo); + } else { + Log.w(LOG, "dictDir is not a diretory: " + getDictDir().getPath()); } if (!toAddSorted.isEmpty()) { Collections.sort(toAddSorted, uncompressedFilenameComparator); diff --git a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java index f7db7de..ba56163 100644 --- a/src/com/hughes/android/dictionary/DictionaryManagerActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryManagerActivity.java @@ -45,7 +45,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import com.hughes.android.dictionary.C.Theme; import com.hughes.android.dictionary.DictionaryInfo.IndexInfo; import com.hughes.android.util.IntentLauncher; import com.hughes.util.StringUtil;