我注意到在 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/