Question

Je remarque que porter un toast n'est pas affiché quand il est utilisé à l'intérieur d'un bloc catch. Est-ce que quelqu'un sait comment montrer des toasts lors de la capture des exceptions? Un exemple:

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

La solution

devrait être comme ceci:

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

Autres conseils

Oui, je l'ai mis juste derrière la ligne existante:

Toast.makeText(this, R.string.txt_file_not_found, Toast.LENGTH_LONG).show();
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top