【发布时间】:2021-07-24 18:27:54
【问题描述】:
我是开发安卓应用的新手。
我想使用 DroidSpeech (https://github.com/vikramezhil/DroidSpeech)
此代码在 [Android 10] 上运行良好。但是,[Android 11] 显示以下错误。
DroidSpeech.java
private void startLanguageReceiver()
{
Log.i("CONTEXT", context.toString());
Intent languageDetailsIntent = RecognizerIntent.getVoiceDetailsIntent(context);
languageDetailsIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
LanguageReceiver languageReceiver = new LanguageReceiver();
languageReceiver.setOnLanguageDetailsListener(new OnLanguageDetailsListener() {
@Override
public void onLanguageDetailsInfo(String defaultLanguage, List<String> otherLanguages) {
dsProperties.currentSpeechLanguage = defaultLanguage;
dsProperties.supportedSpeechLanguages = otherLanguages;
// Initializing the droid speech properties
initDroidSpeechProperties();
if(droidSpeechListener != null)
{
// Sending an update with the current speech language and supported speech languages if applicable
droidSpeechListener.onDroidSpeechSupportedLanguages(dsProperties.currentSpeechLanguage, dsProperties.supportedSpeechLanguages);
}
}
});
// Starting the broadcast receiver to get the language details
context.sendOrderedBroadcast(languageDetailsIntent, null, languageReceiver, null, Activity.RESULT_OK, null, null);
}
这是错误代码
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Intent android.content.Intent.addFlags(int)' on a null object reference
at com.example.Jachi3kki.DroidSpeech.DroidSpeech.startLanguageReceiver(DroidSpeech.java:108)
at com.example.Jachi3kki.DroidSpeech.DroidSpeech.<init>(DroidSpeech.java:83)
at com.example.Jachi3kki.fragment.ViewPagerMainFragment.onCreate(ViewPagerMainFragment.kt:42)
DroidSpeech.java:108 这个
Intent languageDetailsIntent = RecognizerIntent.getVoiceDetailsIntent(context);
DroidSpeech.java:83
startLanguageReceiver();
我试图修复它但失败了。
好像所有变量都初始化了,但是哪里出错了。
我该如何解决?
【问题讨论】:
标签: java android null speech-recognition