gpt4 book ai didi

android - 即使包含 try catch block 后仍出现 IO 异常

转载 作者:行者123 更新时间:2023-11-29 15:35:49 25 4
gpt4 key购买 nike

下面这段代码产生了错误

Activity context;
context = new Activity();
try {
InputStream configAsset = context.getApplicationContext().getAssets().open("MyConfig.cfg");
//SimpleSpkDetSystem alizeSystem = new SimpleSpkDetSystem(configAsset, context.getApplicationContext().getFilesDir().getPath());

}catch (FileNotFoundException e) {
Log.e(LOG_TAG, "File not found for recording ", e);
}

错误:

Error:(255, 87) error: unreported exception IOException; must be caught or declared to be thrown
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

即使在我包含 try、catch block 之后,为什么它会产生错误?

最佳答案

像这样更改您的代码:

之前:

Activity context;
context = new Activity();
try {
InputStream configAsset = context.getApplicationContext().getAssets().open("MyConfig.cfg");
//SimpleSpkDetSystem alizeSystem = new SimpleSpkDetSystem(configAsset, context.getApplicationContext().getFilesDir().getPath());

}catch (FileNotFoundException e) {
Log.e(LOG_TAG, "File not found for recording ", e);
}

之后:

Activity context;
context = new Activity();
try {
InputStream configAsset = context.getApplicationContext().getAssets().open("MyConfig.cfg");
//SimpleSpkDetSystem alizeSystem = new SimpleSpkDetSystem(configAsset, context.getApplicationContext().getFilesDir().getPath());

}catch (IOException e) {
Log.e(LOG_TAG, "File not found for recording ", e);
}

关于android - 即使包含 try catch block 后仍出现 IO 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50599958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com