From 23b59b3cd0c63207906e6702b71f6d3523abcb72 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Wed, 4 Nov 2020 14:08:09 +0530 Subject: [PATCH] Fix issue 1960: Null Pointer Exception in onDestroy of TtsService --- .../src/com/reecedunn/espeak/TtsService.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/android/src/com/reecedunn/espeak/TtsService.java b/android/src/com/reecedunn/espeak/TtsService.java index 2235d4566..d8f7dbf2a 100644 --- a/android/src/com/reecedunn/espeak/TtsService.java +++ b/android/src/com/reecedunn/espeak/TtsService.java @@ -94,7 +94,9 @@ public class TtsService extends TextToSpeechService { if (mOnLanguagesDownloaded != null) { unregisterReceiver(mOnLanguagesDownloaded); } - mAsyncExtract.cancel(true); + if (mAsyncExtract != null) { + mAsyncExtract.cancel(true); + } } /** @@ -120,12 +122,12 @@ public class TtsService extends TextToSpeechService { protected String[] onGetLanguage() { // This is used to specify the language requested from GetSampleText. if (mMatchingVoice == null) { - return new String[] { "eng", "GBR", "" }; + return new String[]{"eng", "GBR", ""}; } - return new String[] { - mMatchingVoice.locale.getISO3Language(), - mMatchingVoice.locale.getISO3Country(), - mMatchingVoice.locale.getVariant() + return new String[]{ + mMatchingVoice.locale.getISO3Language(), + mMatchingVoice.locale.getISO3Country(), + mMatchingVoice.locale.getVariant() }; } @@ -146,17 +148,17 @@ public class TtsService extends TextToSpeechService { final File dataPath = CheckVoiceData.getDataPath(this).getParentFile(); mAsyncExtract = new AsyncExtract(this, R.raw.espeakdata, dataPath) { - @Override - protected void onPostExecute(Integer result) { - switch (result) { - case RESULT_OK: - final Intent intent = new Intent(DownloadVoiceData.BROADCAST_LANGUAGES_UPDATED); - sendBroadcast(intent); - break; - case RESULT_CANCELED: - // Do nothing? - break; - } + @Override + protected void onPostExecute(Integer result) { + switch (result) { + case RESULT_OK: + final Intent intent = new Intent(DownloadVoiceData.BROADCAST_LANGUAGES_UPDATED); + sendBroadcast(intent); + break; + case RESULT_CANCELED: + // Do nothing? + break; + } } }; @@ -320,8 +322,7 @@ public class TtsService extends TextToSpeechService { } } - if (text.startsWith("" preprocessing tags, // so need to remove these before passing to synthesize. text = text.substring(text.indexOf("?>") + 2).trim(); @@ -371,8 +372,8 @@ public class TtsService extends TextToSpeechService { /** - * Begin voice data download here instead of an activity. - */ + * Begin voice data download here instead of an activity. + */ private static final int PROGRESS_STARTING = 0; private static final int PROGRESS_EXTRACTING = 1; -- GitLab