开发者

Toast does not display when used in catch block

开发者 https://www.devze.com 2023-01-22 14:49 出处:网络
I noticed that a toast isn\'t displayed when it\'s used inside a catch block. Does anyone know how to show toasts when catching exceptions? An Example:

I noticed that a toast isn't displayed when it's used inside a catch block. Does anyone know how to show toasts when catching exceptions? An Example:

try {
    // try to open a file
} catch (FileNotFoundException e) {
    Toast.makeText(this, R.string.txt_file_not_found,开发者_高级运维 Toast.LENGTH_LONG);
    return; // cancel processing
}


Should be like this:

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


Yes, I put it right behind the existing line:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号