gpt4 book ai didi

android - 在 catch block 中使用时,Toast 不显示

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:50:06 25 4
gpt4 key购买 nike

我注意到在 catch block 中使用 toast 时不会显示它。有谁知道在捕获异常时如何显示 toast ?一个例子:

try {
// try to open a file
} catch (FileNotFoundException e) {
Toast.makeText(this, R.string.txt_file_not_found, Toast.LENGTH_LONG);
return; // cancel processing
}

最佳答案

应该是这样的:

Toast toast = Toast.makeText(this, R.string.txt_file_not_found, Toast.LENGTH_LONG);
toast.show();

关于android - 在 catch block 中使用时,Toast 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4064718/

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