如何修复空对象引用上的DroidSpeech代码



我是开发android应用程序的新手。

我想使用DroidSpeech(https://github.com/vikramezhil/DroidSpeech)

此代码在[Android10]上运行良好。然而,[Android11]显示以下错误。

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)

java:108这个

Intent languageDetailsIntent =  RecognizerIntent.getVoiceDetailsIntent(context);

DroidSpeech.java:83

startLanguageReceiver();

我试着修理它,但失败了。

看起来所有变量都已初始化,但某个地方出现了错误。

我该如何修复它?

要修复Android 11的此问题,请执行以下步骤

第1步:下载代码zip并在DroidSpeech.java的第103行中进行更改

替换此:Intent languageDetailsIntent = RecognizerIntent.getVoiceDetailsIntent(context);

这样:Intent languageDetailsIntent=Intent(RecognizerIntent.ACTION_RECOGNIZE_PEECH(;

步骤2:将com.vikramezhil.droidspeech包装复制到我的项目并更改应用程序等级

替换此:compile 'com.github.vikramezhil:DroidSpeech:v2.0.3’

有了这个:implementation project(path: ':droidspeech')

相关内容

  • 没有找到相关文章

最新更新