我正在使用執行TTS的Nuance SpeechKit編程應用程序。它要求將上下文(從getApplicationContext()
中調用)傳遞給一些函數。不幸的是,我在日誌中看到這個錯誤:ANDROID_CONTEXT parameter is not passed in!!!
Android編程:ANDROID_CONTEXT參數未通過錯誤
讓我給出更多背景:在主要活動中,它從一個按鈕打開一個對話框。該對話框調用文本到語音功能。因此,我在主要活動中調用getApplicationContext()
,並使用setter將其作爲參數傳遞給我的DialogFragment
。不幸的是,即使我正在調用setter,我也會遇到這個錯誤。那麼會出現什麼問題?下面是一些代碼:
在我的主要活動:
// Instance variables...
private SpeechKit speechKit;
private Context context;
protected void onCreate(Bundle savedInstanceState) {
...
context = getApplicationContext();
...
this.speechKit = SpeechKit.initialize(context,
"CORRECT_API_KEY",
"sslsandbox.nmdp.nuancemobility.net",
443,
true,
SpeechKitAPIKey);
speechKit.connect();
}
public void invokeDialog() {
...
dialogueFragment.setContext(context);
dialogueFragment.setSpeechKit(speechKit);
...
}
而且這裏是我的對話片段代碼:
public void setSpeechKit(SpeechKit speechKit) {
this.speechKit = speechKit;
}
private SpeechKit speechKit;
private Context context;
public void setSpeechKit(SpeechKit speechKit) {
this.speechKit = speechKit;
}
public void setContext(Context context) {
this.context = context;
}
// Called when a button is pushed...
public void narrateText(String voice, String phrase) {
Vocalizer vocalizer = speechKit.createVocalizerWithVoice(voice, this, handler);
vocalizer.speakString(phrase, context);
}
現在我不知道爲什麼這個錯誤被調用。代碼編譯得很好。有什麼建議嗎?
你好。你有沒有發現問題,因爲我現在有同樣的問題? –
我希望我能說我明白了,但我沒有:(......我從此放棄了這個項目,對不起 – user3894009