Je commence à apprendre la programmation Android, et maintenant j'essaie d'afficher un toast avec une chaîne personnalisée.Toast avec message personnalisé
Random r = new Random();
int i = r.nextInt(100 - 90 + 1) + 90;
String message = String.format(r);
Toast.makeText(getApplicationContext(), "@".replace(message), Toast.LENGTH_LONG).show();
Toutes les idées que je fais mal? J'obtiens le message d'erreur suivant:
Error:(40, 40) error: no suitable method found for format(Random) method String.format(String,Object...) is not applicable (argument mismatch; Random cannot be converted to String) method String.format(Locale,String,Object...) is not applicable (argument mismatch; Random cannot be converted to Locale)
Quel est exactement le problème? Avez-vous un message d'erreur? –
Oui. Erreur: (40, 40) erreur: aucune méthode appropriée trouvée pour le format (aléatoire) méthode String.format (String, Object ...) n'est pas applicable (discordance d'argument; Random ne peut pas être converti en chaîne) méthode Chaîne. format (Locale, Chaîne, Objet ...) n'est pas applicable (discordance d'argument; Random ne peut pas être converti en Locale) – Joe
@Joe Je suppose que vous vouliez afficher 'i', donc vous devez le mettre dans' String.format() 'plutôt que votre objet' Random', comme 'String message = String.format (i);' – Jezor